Should WebAPI be loaded in Async?
I have read about ASP.NET WebAPI File Upload on the web and StackOverflow.
All the questions I've seen (directly or indirectly) refer to the sample MSDN article with async upload .
Is this the de facto way to handle file uploads? Should the file be loaded into WebAPI use Task<>
and async
?
source to share
A friend just asked me about this problem, and the short answer is, I believe yes ... with caveats.
The corresponding API is provided by extension methods defined at https://msdn.microsoft.com/en-us/library/system.net.http.httpcontentmultipartextensions(v=vs.118).aspx . I've hunted for synchronous versions of these methods, to no avail.
Obviously, the return value from ReadAsMultipartAsync<T>
is one Task<T>
that you can call Wait()
to force it to sync. Then you can opt out of async in the method declaration in your controller.
I haven't tried it yet, but maybe it works, maybe not, although there is no obvious reason why not.
I guess the question I have to ask is why you want to implement synchronous loading of a given MS, is it quite difficult to get developers to go down the asynchronous route? (Not that this is necessarily good or advisable in all cases.)
source to share