Wednesday, August 5, 2015

Simple explanation and example about how to use FormData with a C# handler

well, you maybe read my prev post about how to send formData, maybe not, check here.

so now we want to build a  handler to get the file.

well the basic thing is that it comes as any other standard request, so

string[] formKeys = Context.Request.Form.AllKeys;
foreach (string key in formKeys) {
        var inputValue = Context.Request.Form[key];

so if its a file, you're type is IList<HttpPostedFile>, like this

IList<HttpPostedFile> file = Convert.ChangeType(
        Context.Request.Form[key], IList<HttpPostedFile>);

and when you have multiple files...

IList<HttpPostedFile> files =

and you must use "readAsDataURL" with the file reader in the client, so it encodes it as Base64, otherwise u'll have hard time to use it.

other than that is kinda simple.

No comments:

Post a Comment