Skip to content

Instantly share code, notes, and snippets.

@Mozu-CS
Last active April 5, 2016 21:51
Show Gist options
  • Save Mozu-CS/d7d56277be8ad1657d56e350a29cbfe7 to your computer and use it in GitHub Desktop.
Save Mozu-CS/d7d56277be8ad1657d56e350a29cbfe7 to your computer and use it in GitHub Desktop.
A working example of how to add an image via the API.
var filePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\Pictures\\";
var fileName = filePath + "bobafett.jpg";
var properties = new JObject();
properties.Add("height", 300);
properties.Add("weight", 300);
var documentResource = new Mozu.Api.Resources.Content.Documentlists.DocumentResource(_apiContext);
var document = new Mozu.Api.Contracts.Content.Document()
{
Name = "bobafett.jpg",
DocumentTypeFQN = "image@mozu",
ContentMimeType = "image/jpeg",
Extension = "jpg",
Properties = properties
};
var file = System.IO.File.OpenRead(fileName);
document.ContentLength = file.Length;
var addedDoc = documentResource.CreateDocumentAsync(document, "files@mozu").Result;
documentResource.UpdateDocumentContentAsync(file, "files@mozu", addedDoc.Id).Wait();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment