Copied to clipboard

Flag this post as spam?

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


  • Rubinho 30 posts 218 karma points
    Jul 07, 2020 @ 13:11
    Rubinho
    0

    Programmatically add items to the mediasection using the UmbracoFileSystemProviders.Azure package

    Hi,

    I add media items programmatically to the mediasection, but now i use the UmbracoFileSystemProviders.Azure package and my files need to be uploaded to Azure.

    This is how i do this normally, but how can i get it in Azure? Is there a build in way, or do i have to upload it manually using the Azure packages on Nuget?

                var relativePath = $"/Media/{someId}/myfile.jpg";
                var path = HttpContext.Current.Server.MapPath(relativePath);
    
                Directory.CreateDirectory(Path.GetDirectoryName(path));
    
                using (var client = new WebClient())
                    client.DownloadFile(data.ItemUrl, path);
    
    
                var media = srv.CreateMedia("SomeName", "SomeId","myDataType");
                media.SetValue("umbracoFile", relativePath);
    
                Services.MediaService.Save(media);
    

    Thanks!

Please Sign in or register to post replies

Write your reply to:

Draft