Read both key values and files from multipart from data post request in ASP.NET WebAPI -
i have endpoint needs accept file upload , other information client request. following code can upload file can't seem figure out how read other info.
i make test request postman following form data:
image -- myimage.jpg -- of type file
email -- a@b.com -- of type text
the backend code looks this:
[httppost] public async task<httpresponsemessage> sharephoto() { try { var provider = new multipartmemorystreamprovider(); var data = await request.content.readasmultipartasync(provider); // how image succesfully passing emailservice var item = (streamcontent)provider.contents[0]; using (var stream = new memorystream()) { await item.copytoasync(stream); string emailaddress; emailservice.sendsharedphoto(emailaddress, stream); return request.createresponse(); } } catch { // stuff } }
in example able access provider.contents[1]
can't seem able value emailaddress
. i'm thinking may possible use same trick await item.copytoasync(stream)
image upload, i'm hoping can simpler solution that. ideas?
i barely answered similar question yesterday. see answer here complete sample controller code.
Comments
Post a Comment