I'm working on an Android App which communicates with a WebApi .NET project in order to insert and get date from database, common case. I've tried to use Multipart MIME. So I've used the following code:
public async Task<HttpResponseMessage> ManageProfilePicture()
{
if (!Request.Content.IsMimeMultipartContent())
{
throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
}
string root = HttpContext.Current.Server.MapPath("~/App_Data");
var provider = new MultipartFormDataStreamProvider(root);
var task = await Request.Content.ReadAsMultipartAsync(provider).
ContinueWith<HttpResponseMessage>(t =>
{
if (t.IsFaulted || t.IsCanceled)
{
Request.CreateErrorResponse(HttpStatusCode.InternalServerError, t.Exception);
}
String fileName = provider.FileData[0].Headers.ContentDisposition.FileName;
return Request.CreateResponse(HttpStatusCode.OK);
});
return task;
}
I'm able to get the file name and other informations about the uploaded file. How could I get the byte array associated to the uploaded file in order to save it in MS SQL Server ? Maybe it's better to recreate the picture in a accessable folder than store it in the database...
Someone could help me with that ?