Copied to clipboard

Flag this post as spam?

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


  • mizzle 91 posts 326 karma points
    Jun 03, 2019 @ 16:29
    mizzle
    0

    Upload (image) file from visitor-submitted form.

    I need an upload field for a contact form that will both save an image to a folder (in the media section or otherwise) and generate a file path that could be inserted into the contact email that editors/admins receive.

    Using this guide, I was able to set up the file upload section and successfully receive the name of the file rendered as a string, but it leaves out any code that would actually upload the file to a folder, assuming the developer would already know that information. I do not know that information.

  • Mario Lopez 168 posts 958 karma points MVP 4x c-trib
    Jun 04, 2019 @ 00:13
    Mario Lopez
    102
    public void CreateMedia(HttpPostedFileBase postedFile)
            {
                // Folder where you want to store the media item.
                var parentMediaFolder = Services.MediaService.GetById(1234); 
    
                // Create a media item
                var node = Services.MediaService.CreateMediaWithIdentity(postedFile.FileName, parentMediaFolder, "Image");
    
                //Assign your file to the Media node. To get this SetValue extension you have to use the Umbraco.Core.Models namespace.
                node.SetValue("umbracoFile", postedFile);
    
                //Save you node values
                Services.MediaService.Save(node);
            }
    
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies