Question

I am using AWS S3 Async upload function to upload a file to S3.

tu.BeginUpload(ur, new AsyncCallback(FinishedAsyncUpload),ms);

ms = Memory Stream

tu.InputStream = ms

My problem is that I want to dispose the Stream after the file has been uploaded. I create a callback function called FinishedAsyncUpload. I also pass the MemoryStream (ms) and dispose it in this function.

 protected void FinishedAsyncUpload(IAsyncResult result)
    {
        ((MemoryStream)result.AsyncState).Dispose();
    }

My problem is that when I try to dispose the memory stream in the callback function, I see that the object doesn't contain any data and asking for length throws (System.objectDisposedException).

How can I dispose the memoryStream after the file has been uploaded?

Was it helpful?

Solution

I am admittedly not familiar with the AWS API specifically, but typically System.ObjectDisposedException is only thrown when Dispose() is called on an already-disposed object. So it may be that the AWS API is disposing of the processed stream for you.

From MSDN for reference:

ObjectDisposedException Class

The exception that is thrown when an operation is performed on a disposed object.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top