It's been quite a while since my last visit to the umbraco world. However I have a project now where I would like to create some content nodes via my Controller.
I'm utilizing the ContentService which works fine for most fields. However for my property field where i have a Umbraco.UploadField things are not really working as expected.
I've triede byte array etc. But not sucessfully. Please see controller snippet below.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Web;
namespace Website.Controllers
{
public class RequestTuneController : Umbraco.Web.Mvc.SurfaceController
{
public ActionResult Index()
{
return Content("hello world");
}
[HttpPost]
[Authorize]
public ActionResult FormPost(Models.RequestTuneModel model)
{
var service = Services.ContentService;
var content = service.Create("name", 1088, "TuningFile", -1);
Unfortunately it's not that simple. Content items don't store the raw contetns of a file on them in an way. They store paths to the file in question, even is this is an "uploaded" one.
This blog post from Paul Seal talks about uploading media items from the front end of your site:
I believe he's storing them in the media library, once you've done that you can have the property on your doc type as a media picker and set the value of that. Alternatively, you can push the file to the file system and then correctly set data on your content item. To find out what this value needs to look like, I advise manually creating a piece of content with an uploaded file, then examining the database to understand how that property value is represented in the umbracoPropertyData table :-)
When I use the interface for a content node that has a Umbraco.FileUpload I dont see that specific file in the media section? So I'm strugling abit to understand why when doing the file upload programaticly I have to place my files in the media content library ?
ContentService.SetValue file
It's been quite a while since my last visit to the umbraco world. However I have a project now where I would like to create some content nodes via my Controller.
I'm utilizing the ContentService which works fine for most fields. However for my property field where i have a Umbraco.UploadField things are not really working as expected.
I've triede byte array etc. But not sucessfully. Please see controller snippet below.
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Web; using System.Web.Mvc; using Umbraco.Core; using Umbraco.Core.Models; using Umbraco.Web;
namespace Website.Controllers { public class RequestTuneController : Umbraco.Web.Mvc.SurfaceController { public ActionResult Index() { return Content("hello world"); } [HttpPost] [Authorize] public ActionResult FormPost(Models.RequestTuneModel model) { var service = Services.ContentService; var content = service.Create("name", 1088, "TuningFile", -1);
}
Hi Jais,
Unfortunately it's not that simple. Content items don't store the raw contetns of a file on them in an way. They store paths to the file in question, even is this is an "uploaded" one.
This blog post from Paul Seal talks about uploading media items from the front end of your site:
https://codeshare.co.uk/blog/how-to-upload-a-file-to-umbraco-from-a-front-end-form/
I believe he's storing them in the media library, once you've done that you can have the property on your doc type as a media picker and set the value of that. Alternatively, you can push the file to the file system and then correctly set data on your content item. To find out what this value needs to look like, I advise manually creating a piece of content with an uploaded file, then examining the database to understand how that property value is represented in the umbracoPropertyData table :-)
Cheers
Nik
Hi Nik.
When I use the interface for a content node that has a Umbraco.FileUpload I dont see that specific file in the media section? So I'm strugling abit to understand why when doing the file upload programaticly I have to place my files in the media content library ?
Here is what i ended up doing if anyone faces the same issue :) my requestTuneModel.File is just a HttpPostedFileWrapper
is working on a reply...