Closed ghost closed 4 years ago
When uploading images the Image media type will be an Image Cropper, which takes an object like is shown in the sample below
var media = new Net.Management.Models.Media {Name = mediaName, MediaTypeAlias = "Image", ParentId = folderId};
media.SetValue("umbracoFile", new { src = fileName }, new FileInfoPart(new FileInfo(imagePath), fileName, $"image/{extension}"));
var image = await managementService.Media.Create(media);
When uploading a PDF try doing this instead
var media = new Net.Management.Models.Media {Name = mediaName, MediaTypeAlias = "File", ParentId = folderId};
media.SetValue("umbracoFile", fileName, new FileInfoPart(new FileInfo(imagePath), fileName, $"application/pdf"));
var image = await managementService.Media.Create(media);
We can add a sample for uploading a file as well, so it shows both Image and File uploads.
Changing the code as suggested works. Thanks :)
I am using the .Net Core Client Library to create and upload new media items with the Content Management API's Media.Create-endpoint. For some reason this only seems to work for image-files (.png, .jpg...) but not for other types (.txt, .pdf... when MediaTypeAlias is set to "File" instead of "Image"). Is the API broken? Or is something wrong with the way I am using the API? I have not found any clues in the API-documentation or elsewhere.
Besides my own code I have also tried the provided console-sample-application. It has only been coded to demonstrate how images can be uploaded. But changing the code a bit (MediaTypeAlias and ContentType) produces the same result (Media-items without content).
I have gathered some more details that might be useful in understanding/recreating/analyzing the problem (code-snippet, screenshots from Umbraco Backoffice, Fiddler's capture of request/response for the API-call): Issue creating media items with Content Management API's Media.Create-endpoint.pdf