Last active
April 5, 2016 21:51
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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