I need to create a media item in code (surface controller) as part of an upload process, get the UDI, and associate another doctype to it. This process is generally working, but after the media item is created (see code below), I can go to the backoffice to see the Size and Type for the media item are empty. Sorting the parent (media folder node) manually, resolves both issues. How can I prevent the issue? Or should I try to sort all child items in the parent programmatically each time an upload occurs?
Backstory:
This bit of code broke for us when upgrading from v7 to v8. Migrating from mediaService.SetMediaFileContent to mediaService.SetValue and fixing a couple of data types on a related doctype seems to allow the process to complete, but with the limitations mentioned.
System.IO.Stream MyStream;
MyStream = model.File.InputStream;
var mediaService = Services.MediaService;
//** Generate Media node **
// Assumes parent ID
var newFileUpload = mediaService.CreateMedia( model.Name, 5016, Constants.Conventions.MediaTypes.File, -1);
newFileUpload.SetValue(Services.ContentTypeBaseServices, Constants.Conventions.Media.File, "TestName.csv", MyStream);
// save the new media node
mediaService.Save(newFileUpload, -1, false);
// generate UDI for new media node
var resultUdi = Udi.Create(Constants.UdiEntityType.Media, newFileUpload.Key); //Association made using this
v8.6 Media Item created without size, type - resort parent resolves issues
I need to create a media item in code (surface controller) as part of an upload process, get the UDI, and associate another doctype to it. This process is generally working, but after the media item is created (see code below), I can go to the backoffice to see the Size and Type for the media item are empty. Sorting the parent (media folder node) manually, resolves both issues. How can I prevent the issue? Or should I try to sort all child items in the parent programmatically each time an upload occurs?
Backstory: This bit of code broke for us when upgrading from v7 to v8. Migrating from mediaService.SetMediaFileContent to mediaService.SetValue and fixing a couple of data types on a related doctype seems to allow the process to complete, but with the limitations mentioned.
I'm following the examples here: https://our.umbraco.com/documentation/reference/management/services/mediaservice/#creating-a-new-media-item-from-a-stream
Hi,
I have the same problem, did you find a solution?
Umbraco 8.6.1
is working on a reply...