I use the Amazon SDK, and I have a method that returns a Stream for an object stored in the Amazon S3 service.
It contains something like this:
var request = new GetObjectRequest().WithBucketName(bucketName).WithKey(keyName); using (var response = client.GetObject(request)) { return response.ResponseStream; }
Obviously, in this case, the stream is not read from the calling method, because the request object was deleted, and when this is done, it closes the stream.
I do not want to upload the file to a MemoryStream or FileStream.
If I do not use the use clause, the garbage collector will delete the request object at some point, so I cannot just not use it.
I ask, is there a way to wrap or copy a stream to another stream and then return it without downloading the file?
I am using .NET 3.5.
Edit: The method inherits from the abstract class, and the caller method does not know that it works with Amazon. Therefore, it must return the stream.
spakinz
source share