I am trying to upload a file from a client to a MVC application, and then have the MVC application pass the upload file to a web api.
So far I overrode the IHostBufferPolicySelector to stream any incoming HTTP requests that are greater than a given size. So any large file uploads made to MVC is being received as a stream.
I thought of two solutions to this problem, but open to any suggestions.
Have MVC temporarily store the file, then send that file over to the web api
Somehow pass the stream of the file that is coming into MVC, over to the web api
Is there a way to achieve option 2? Can I pass an incoming stream to another web service?
Related
I created some chrome extension that detects a file download event and cancel the download, and gets the download link. Sends the link to myserver.
I want to create a server that recive link to download, download the file, do some manipulation on the file and sends the file back to client.
All the time I developed client side apps (Mainly with c#), and I don't know what to choose for the server side, WCF App or Web API (or something else). the server can be inside the organisation or remote.
What do you think should I pick? any suggestions?
It seems that creating Restful-style services may be more appropriate for this scenario.
You know, both WCF and Asp.net WebAPI can create Restful-style services. WCF could take advantage of the Webhttpbinding to create it.
As for handling file uploads and downloads, I don't think there is any difference between the two techniques. Perhaps the services created by Asp.net WebAPI are a little more mature, such as the ability to deal with form-data stream (multipart/form-data) directly. While WCF service could not directly process the form-data stream.
Here is an example of an upload and download in Asp.net WebAPI.
https://learn.microsoft.com/en-us/aspnet/web-api/overview/advanced/sending-html-form-data-part-2
How to return a file (FileContentResult) in ASP.NET WebAPI
Feel free to let me know if there is anything I can help with.
I dont find any tutorials on how to upload folder and its contents to rest web service using c#? The content-type is application/json. Is there any way to do this?
I am trying to create a Web API controller to post a file to a storage service like Azure storage for example. The web api client is an AngularJS web page. The issue now is the progress bar on the file upload is showing 100% without sending any bytes to the backend storage service. I did turn off the buffering on uploads. Is there a way send the bytes to the backend storage as we receive them from the web api client? Is this possible with HttpClient in .NET 4.5?
I have the following architecture:
Web-Application <-> Web-Service <-> Cloud
The web-application provides a html page for uploading a file which should be placed in the cloud. It is, by design, not possible to upload directly to the cloud (this is really no option here).
What I could do is, to upload it to the web-application and save the file to disk, then upload it to the web-service, save to disk and finally upload it to the cloud. But because the file could be large (4GB+) it would be nice just to pass the stream from the web-application to the web-service and the web-service passes it to the cloud, so it does not get saved to file anywhere instead of the cloud.
Is this possible with C#, .NET 4, ASP.NET and MVC 4?
It was really easy.
Within my Web-Application Action I just created a new HttpWebRequest, copied the file's inputstream to the HttpWebRequest and sent it to the Web-Service. Same thing from Web-Service to the Cloud. So no storage to disk is needed.
I am trying to figure out how to stream a file (typically a PDF) from a web service that is front ended by a typical web site. The PDFs do not physically exist, but are created on the fly by a report generator (think Crystal, Telerik Reporting, etc.)
I can do this today directly from the web site by doing a Response.Clear() followed by setting the ContentType and adding the appropriate Content-Disposition header finally followed up by a Response.BinaryWrite(...).
But, a WCF service (IIS hosted in this case), does not have a Response object. I have tried passing in the Response object from my web page as a parameter, but I can't even start the WCF Service because HttpResponse cannot be serialized.
Am I barking up the wrong tree? Is there a better way of looking at this? We wanted it in a common web service because more of our web sites are needing to do this and we don't want to maintain multiple copies of the code to do it.
You can send your file as byte[] array.
Or you can send this file as a Stream parameter (using Streamed mode)