This project is read-only.

Handle file upload in custom field editor events

Topics: Writing modules
Feb 15, 2012 at 12:10 PM

Hi all, I have a custom field similar to the Image Field by Sébastien. The field allows a user to upload an image using the MediaService. I'm trying to allow a default image to be uploaded in the field settings, but I don't know how to handle the form post. In Sébastien's module he modifies the encoding type of the form using jQuery:


    .attr('enctype', 'multipart/form-data')
    .attr('encoding', 'multipart/form-data'); // ie issue


This works fine, and in the Driver the following line gets the file from the request, "updater" is the AdminController:


var postedFile = ((Controller)updater).Request.Files["image-" + field.Name];


However, when it comes to the PartFieldEditorUpdate event in my ImageFieldEditorEvents class I want to do a similar thing, but the line above throws an exception because "updater" is an instance of Orchard.ContentTypes.Services.ContentDefinitionService.Updater, which cannot be cast to a "Controller".

How can I get the file from the form in the content definition editor?

Thanks for your time, Greg.

Feb 16, 2012 at 9:15 AM

In case anyone's interested - I solved the issue by using the WorkContext property of the injected IOrchardServices: