Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DropbboxClient Upload closes Stream #340

Open
glindstr opened this issue Jan 13, 2023 · 1 comment
Open

DropbboxClient Upload closes Stream #340

glindstr opened this issue Jan 13, 2023 · 1 comment
Labels

Comments

@glindstr
Copy link

glindstr commented Jan 13, 2023

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.

@glindstr glindstr added the bug label Jan 13, 2023
@greg-db
Copy link
Contributor

greg-db commented Jan 16, 2023

Thanks for writing this up! I'll ask the team to look into changing this behavior and offer options for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants