Hi, I found a code sample for uploading multiple files to a webapi controller.
Now I am not sure how to rename to files created on the server, as the files are named like this:
BodyPart_003fa560-908b-4d94-bed0-ac0532a09a66
This is how the code sample looks:
string root = HttpContext.Current.Server.MapPath("~/Upload/" + IncidentId);
var provider = new MultipartFormDataStreamProvider(root);
try
{
StringBuilder sb = new StringBuilder();
await Request.Content.ReadAsMultipartAsync(provider);
foreach (var key in provider.FormData.AllKeys)
{
foreach (var val in provider.FormData.GetValues(key))
{
sb.Append(string.Format("{0}: {1}\n", key, val));
}
}
foreach (var file in provider.FileData)
{
sb.Append(string.Format("Uploaded file: {0} ({1} bytes)\n", fileInfo.Name, fileInfo.Length));
}
return new HttpResponseMessage()
{
Content = new StringContent(sb.ToString())
};
}
catch (System.Exception e)
{
return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e);
}
Yes, i know that the Upload folder will be publicly accessible. This is for testing purposes only at the moment.
So the question is: how do I rename the files, or is there a way to save the files directly with the correct name provided in the HTTP POST?