dropbox-sdk-dotnet
dropbox-sdk-dotnet copied to clipboard
DropbboxClient Upload closes Stream
When calling a DropboxClient to upload a file via a stream, the function has the side effect of closing the stream:
using var dropbboxClient = new DropboxClient("apitoken");
using var stream = new MemoryStream(Encoding.UTF8.GetBytes("a text file"));
var request = new UploadArg("my new text file.txt");
var result = await dropbboxClient.Files.UploadAsync(request, stream);
stream.Seek(0, SeekOrigin.Begin); //Exception. Stream is closed
What happens: dropbboxClient.Files.UploadAsync closes the stream after upload.
What should happen: dropbboxClient.Files.UploadAsync should not close the stream. This is a hidden side effect that shouldn't happen.
Temporary Workaround: Copy the stream into another stream.
AWS has some nice convenience features parallel to this with their s3 SDK.
var putRequest = new PutObjectRequest()
{
BucketName = Bucket,
Key = s3FileKey,
AutoCloseStream = false,
AutoResetStreamPosition = true,
InputStream = stream,
};
The default of the sdk should be to NOT close the stream as this is a hidden side effect. However a nice enhancement would be to provide convenience properties in the class UploadArg of "AutoCloseStream" and "AutoResetStreamPosition" which can be set.
Thank you for reviewing.
Thanks for writing this up! I'll ask the team to look into changing this behavior and offer options for it.