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.
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);
}
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.
is working on a reply...