C#
- 10 ответов
- 0 вопросов
5
Вклад в тег
[HttpPost()]
public async Task<HttpResponseMessage> Post()
{
if (!Request.Content.IsMimeMultipartContent())
{
throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
}
var streamProvider = new MultipartFormDataStreamProvider(@"C:\Uploads");
List<string> files = new List<string>();
try
{
// Read the MIME multipart content using the stream provider we just created.
await Request.Content.ReadAsMultipartAsync(streamProvider);
//await Request.Content.ReadAsMultipartAsync();
foreach (MultipartFileData file in streamProvider.FileData)
{
files.Add(file.LocalFileName);
}
// Send OK Response along with saved file names to the client.
return Request.CreateResponse(HttpStatusCode.OK, files);
}
catch (Exception e)
{
return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e);
}
}