How to add image to product in module ?

Topics: Customizing Orchard
Nov 27, 2013 at 3:07 PM
Edited Nov 27, 2013 at 3:12 PM
Hi everyone,

as picture, i created file type in module, but when i click submit button, i can't get that file type from Editor method of Driver. How can i save it to Media folder and Database ?



Thank you very much.
Nov 27, 2013 at 8:15 PM
You can access the posted files from your driver by injecting IHttpContextAccessor, which provides you with the current HttpContext.
Marked as answer by phuochuy on 11/27/2013 at 5:43 PM
Nov 28, 2013 at 12:19 AM
Edited Nov 28, 2013 at 12:43 AM
Thank you, SkyWalker, i got it.
Nov 28, 2013 at 12:47 AM
Edited Nov 28, 2013 at 12:48 AM
which method can i get Media's path ?
Nov 29, 2013 at 8:22 AM
If you inject IMediaService and/or IStorageProvider, you will be able to work with the Media folder.
Marked as answer by phuochuy on 11/29/2013 at 2:10 AM
Nov 29, 2013 at 9:11 AM
Edited Nov 29, 2013 at 9:13 AM
Thank you walker,

i gonna try to it.

by the way, could you help me for ?
Nov 29, 2013 at 9:32 AM
Edited Nov 29, 2013 at 9:42 AM
i recently try to it with command
__private readonly MediaService _mediaService;__

protected override DriverResult Editor(ProductPart part, IUpdateModel updater, dynamic shapeHelper)
            var file = HttpContext.Current.Request.Files["Image"];
            if (file != null && file.ContentLength != 0)
                //var mediaPart = _mediaLibraryService.ImportMedia(file.InputStream, "ProductImages", file.FileName);
                var uploadStr = _mediaService.UploadMediaFile("ProductImages", file.FileName, file.InputStream, false);
            updater.TryUpdateModel(part, Prefix, null, null);
            return Editor(part, shapeHelper);
it doesn't work, the cause as link above, id = 471374.
could not execute query
[ SELECT TOP (@p0)  this_.Id as Id37_2_, this_.Number as Number37_2_, this_.Published as Published37_2_, this_.Latest as Latest37_2_, this_.Data as Data37_2_, this_.ContentItemRecord_id as ContentI6_37_2_, contentite1_.Id as Id36_0_, contentite1_.Data as Data36_0_, contentite1_.ContentType_id as