Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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?
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:
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
I have the same problem, did you find a solution?
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted