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 =
    Context.Request.Files.GetMultiple(key);

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.

Comments

Popular posts from this blog

c# Service Play Sound with NAudio example by Moshe

SOLVED The item could not be indexed successfully because the item failed in the indexing subsystem

JS/JQ simulate Enter event