Jesus / dropbox_api

Ruby client library for Dropbox API v2
MIT License
171 stars 113 forks source link

Incorrect Content-Length when #upload passed string #39

Closed ntippie closed 6 years ago

ntippie commented 6 years ago

I noticed that when the #upload method is given a string (like the result of IO.read), the uploaded file is not the correct size.

result1 = service.upload('/test1.png', IO.read('/tmp/test.png'))
result1.size
=> 6208

File.open('/tmp/test.png') do |file|
  result2 = service.upload('/test2.png', file)
end
result2.size
=> 6477

File.size('/tmp/test.png')
=> 6477

I compared the content of the two files and they are identical up until test1's premature end (it is missing the last 269 bytes).

I traced the issue to here. I believe the first priority method to call should be #bytesize, which will get the proper size in bytes. I'd be happy to submit a PR if you agree.

Jesus commented 6 years ago

That's interesting, thanks for your report.

I can't look into it with detail right now but will try to reproduce it this week.

Jesus commented 6 years ago

I'm a bit confused, I think you're passing the path to the local file rather than the file contents, as the method expects. This is documented here: http://www.xuuso.com/dropbox_api/DropboxApi/Client.html#upload-instance_method

What's the value of save_path in your first example?

If you pass the path to a file, this'll be saved in Dropbox as the content of your file.

ntippie commented 6 years ago

I'm sorry, I documented it incorrectly. I've updated the original post.

Jesus commented 6 years ago

I see now, thanks for your report!

I'll release a new version including this fix as soon as I get a chance, over the next few days.