Download file from streamcontent
· For example, when we send the file type as PDF, service will return PDF file if we send Doc, service will return Word document. (I have taken this sample to cover all types of files). We cannot send the file from its original state. To send the file to REST service, we have to follow the below steps. Convert Required file into Bytes. Thanks @ryancyq I have added the WrapResult to the method and tested the method using swagger api and inserted a file id from the database but it still doesn't download the file: `Here is the code: /// /// Download the file from the database by id. · From an bltadwin.ru Web Api 2.x controller I'm am serving files using an instance of the StreamContent type. When a file is requested, its blob is located in the database, and a blob stream is opened. The blob stream is then used as input to a StreamContent instance. Boiled down, my controller action looks similar to this.
To download the object, you create a GetObjectRequest object with the bucket name and the object Key that you want to retrieve and then pass that to AmazonS3Client's GetObject method. You can write the object to the file system using WriteResponseStreamToFile() method of the GetObjectResponse. Fooling myself I didn't notice that one cannot do bltadwin.ru(filePath); before returning the file because it'll be deleted from the server disk before arriving at the client - see that bltadwin.rut receives a StreamContent, that is, the file is yet to be streamed to the client - only after it's been streamed is that we can delete. And there is a similar post on SO: Returning binary file from controller in bltadwin.ru Web API. It talks about output an existing file. But I could not make it work with a stream. Any suggestions? Solution. Instead of returning StreamContent as the Content, I can make it work with ByteArrayContent.
To download a partial range of bytes from the file, your app can use the Range header as specified in RFC Note that you must append the Range header to the actual @bltadwin.ruadUrl URL and not to the request for /content. From an bltadwin.ru Web Api 2.x controller I'm am serving files using an instance of the StreamContent type. When a file is requested, its blob is located in the database, and a blob stream is opened. The blob stream is then used as input to a StreamContent instance. Boiled down, my controller action looks similar to this. To download the object, you create a GetObjectRequest object with the bucket name and the object Key that you want to retrieve and then pass that to AmazonS3Client’s GetObject method. You can write the object to the file system using WriteResponseStreamToFile() method of the GetObjectResponse.
0コメント