Jesus / dropbox_api

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

Uploading large files #6

Closed TrevorHinesley closed 7 years ago

TrevorHinesley commented 7 years ago

What is the best way to upload a large file? I see the documentation mentions something about uploading over 150MB files, but am unsure how to actually implement it. Since it takes a string, is it possible to actually accept a file stream or something so as not to load a massive file into memory and convert it to a string?

Jesus commented 7 years ago

I can see the documentation of this endpoint is wrong and incomplete. I'll update it now.

Here's an example of how you can upload a file.

client = DropboxApi::Client.new YOUR_TOKEN
file_content = IO.read "image.png"
client.upload "/dropbox/path/image.png", file_content

As you pointed out, this implies that you need to load the full file in memory. This is bad so a PR would be welcome.

This is using the upload HTTP endpoint of Dropbox API. If you need to upload a file larger than 150MB, this endpoint won't work. You'll have to use the upload_session/* endpoints, which unfortunately haven't been implemented yet.

TrevorHinesley commented 7 years ago

Thanks a ton! If I get a chance I'll try to add that endpoint in.