Answer the question
In order to leave comments, you need to log in
How to upload a file in ASP.NET WebApi without writing it to disk?
In all examples, uploading a file to the web api is done through
var provider = new MultipartFormDataStreamProvider(path);
var result = await Request.Content.ReadAsMultipartAsync(provider);
Answer the question
In order to leave comments, you need to log in
Here is the solution:
var provider = new MultipartMemoryStreamProvider();
var result = await content.ReadAsMultipartAsync(provider);
var stream = provider.Contents[0]; // если гарантированно один файл передавался, иначе - пройдитесь с помощью foreach
var fileName = stream.Headers.ContentDisposition.FileName.Trim('"');
var imgStream = await stream.ReadAsStreamAsync();
var img = GetImageResize(Image.FromStream(imgStream), width, height);
img.Save($"{basePath}\\{fileName}");
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question