Copied to clipboard

Flag this post as spam?

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


  • mizzle 47 posts 169 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 99 posts 663 karma points c-trib
    Jun 04, 2019 @ 00:13
    Mario
    100
    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);
            }
    
Please Sign in or register to post replies

Write your reply to:

Draft