Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • baile185 2 posts 22 karma points
    Aug 19, 2020 @ 14:11
    baile185
    0

    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

    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
    
  • Carsten Nørregaard Panek 34 posts 124 karma points
    Sep 25, 2020 @ 10:41
    Carsten Nørregaard Panek
    0

    Hi,

    I have the same problem, did you find a solution?

    Umbraco 8.6.1

Please Sign in or register to post replies

Write your reply to:

Draft