GetObjectAsync object stream couldn't use on the new FileStreamResult
See original GitHub issueI try use GetObjectAsync (Downloads an object as a stream.) and I would like to use stream on FileStreamResult. I can set it but when GetObjectAsync method finish my FileStreamResult.FileStream contentbytes go 0. You can follow the attaches. GetObjectAsync hasn’t a return type.
My old response and return value with S3.Model
var file = await _storage.Download(bucket, key);
var result = new FileStreamResult(file.ResponseStream, file.Headers.ContentType)
{
FileDownloadName = temp.Name + type,
LastModified = file.LastModified,
EntityTag = new EntityTagHeaderValue(file.ETag)
};
MinioClient
When I use with this code, i get that
ObjectDisposedException: Cannot access a closed Stream.
using (Stream strm = new MemoryStream())
{
await _storage.Client1.GetObjectAsync(bucket, key, async stream => { await stream.CopyToAsync(strm); });
fileStreamResult = new FileStreamResult(strm, file.Headers.ContentType)
{
FileDownloadName = temp.Name + type,
LastModified = DateTimeOffset.Now,
EntityTag = new EntityTagHeaderValue(file.ETag)
};
return fileStreamResult;
}
then i try to it with this code,
await _storage.Client1.GetObjectAsync(bucket, key, stream =>
{
fileStreamResult = new FileStreamResult(stream, file.Headers.ContentType)
{
FileDownloadName = temp.Name + type,
LastModified = DateTimeOffset.Now,
EntityTag = new EntityTagHeaderValue(file.ETag)
};
});
return fileStreamResult;
It sets to file stream and when finish the GetObjectAsync method, it set to fileStreamResult.FileStream contentBytes as 0 automaticly.
How i can fix this.
Thank you.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Stream S3 file via .NET FileStreamResult and Web API
1 Answer. Seems FileStreamResult will handle disposing of the stream internally.
Read more >Get an object from an Amazon S3 bucket using an AWS SDK
Get an object from an Amazon S3 bucket using an AWS SDK. ... GetObjectAsync(request); try { // Save object to local file await...
Read more >Asynchronously processing GetObjectAsync stream #420
For the time being, I came up with a workaround using TaskCompletionSource, although I cannot test if it is truly asynchronous or blocking....
Read more >FileStreamResult does not indicate download start
Well, the simple answer seems to be: The download start & progress are not visible in browser, because the content length is not...
Read more >FileStreamResult Class (Microsoft.AspNetCore.Mvc)
Represents an ActionResult that when executed will write a file from a stream to the response.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@hyfree, The issue was with the async lambda function (
Action<Stream>
) used inGetObjectAsync
callback. So,Func<Stream, CancellationToken, Task>
support is added to properly await async methods, likeStream
’sCopyToAsync
.@onurbos, @hyfree, Please follow PR#730, which is currently in the code review process. You can also check the functional test
GetObject_AsyncCallback_Test1
inMinio.Functional.Tests/FunctionalTest.cs
. The fix will be available as soon as the PR is merged and a new MinIO release is created fornuget.org
. I anticipate it’ll be available in the next couple of weeks.Please upgrade to the latest release.