Closed davidpodhola closed 11 years ago
The dynamic model binder was authored to help with the serialization of json data, here is the class for reference:
https://github.com/amirrajan/Oak/blob/master/Oak/ParamsModelBinder.cs
If you want to get access to a file you can use the static model binders that come with mvc (specifically HttpPostedFileBase). I believe this file is still relevent:
http://haacked.com/archive/2010/07/16/uploading-files-with-aspnetmvc.aspx
Another option may be to access the file via the HttpContext.Request.Files collection within the controller.
Any ideas how the dynamic model binder can be enhance to include files?
Thanks! Unfortunately HttpContext.Request.Files
does not work. Request.Files.Count
shows 0. If I dereference @params.scan
, I get @params.scan "C:\\Users\\david_000\\Desktop\\SKMBT_C22013021514280-signed.pdf" dynamic {string}
. Will try static model binders.
Would it be helpful if asking for file returned a byte array? It may be possible to pull that off. Would it be something you'd want to try (we can pair on it some time if you want)?
Yes, that would be perfect, I need byte[] to encode64 it and upload to Dynamics CRM Online. If there is anything to download and test, please let me know, thanks!
Od:Amir Rajan Odesláno:20.4.2013 18:52 Komu:amirrajan/Oak Kopie:David Podhola Pøedmìt:Re: [Oak] How to get uploaded file content? (#25)
Would it be helpful if asking for file returned a byte array? It may be possible to pull that off. Would it be something you'd want to try (we can pair on it some time if you want)?
— Reply to this email directly or view it on GitHubhttps://github.com/amirrajan/Oak/issues/25#issuecomment-16707184.
I am definitely missing something, however simply adding public HttpPostedFileBase scan { get; set; }
to my public class ContractForm : DynamicModel
do not work. Adding HttpPostedFileBase scan
as a second parameter to public dynamic AddCommitPrint(ContractForm @params, HttpPostedFileBase scan)
neither.
Forgot to mention - I am doing all this in MVC 4 to be Azure compatible.
this worked for me: https://gist.github.com/amirrajan/5460334
Keep in mind that most cloud based servers do not give you access to the file system, so you'll have to find other means to save the file (maybe in the DB or blog storage...I don't have much experience with that).
Let me know if this works for you.
Working, thanks a lot!
I need to upload a file. I add
<input type="file" id="scan" name="scan" />
to a view. Now in the Controller I need to read the content. I tried usingRequest.Files
and also tried to dereference@params
, but no luck. Please suggest how to get uploaded file content. Thanks!