1

I want to overwrite an existing file on Dropbox.

Here's the code I'm using (based on the docs):

require 'dropbox_sdk'

ACCESS_TOKEN = '###'

client = DropboxClient.new(ACCESS_TOKEN)

file = open('/source_folder/file1.csv')
response = client.put_file('/target_folder/file1.csv', file, true)
puts "uploaded:", response.inspect

This does not overwrite the existing file. I check this by looking at the directory it's in. It contains the old version instead of the new.

response.inspect returns:

{"rev"=>"9e6b400e64803", "thumb_exists"=>false, "path"=>"/target_folder/file1.csv", "is_dir"=>false, "client_mtime"=>"Sun, 07 Sep 2014 14:56:35 +0000", "icon"=>"page_white", "bytes"=>14705913, "modified"=>"Sun, 07 Sep 2014 14:56:35 +0000", "size"=>"14 MB", "root"=>"dropbox", "mime_type"=>"text/csv", "revision"=>648884}

What should I try next?

5
  • It certainly looks like it's working. When you say "This doesn't do anything with the file," what do you mean? How are you checking? You might want to use client.get_file to retrieve the latest version of the file from the server to see what made it there. Also, make sure that your local file (/source_folder/file1.csv) is actually what you expect it to be. Commented Sep 7, 2014 at 16:14
  • This does not overwrite the existing file. I check this by looking at the directory it's in. It contains the old version instead of the new. Commented Sep 7, 2014 at 16:22
  • On the local machine, you mean? Perhaps your Dropbox client is not running or is somehow stuck, or perhaps you're writing the file to the wrong account or to a different path than you thought. I'd suggest calling the API to double-check what made it to the server so you can narrow down the issue. Commented Sep 7, 2014 at 16:47
  • Yes on my local machine. The Dropbox client is running and working perfectly. I'm writing the file to the correct account and to the correct path. My workaround is to delete the file first, then upload a new one, until I fix the overwrite. Commented Sep 7, 2014 at 20:14
  • So your evidence for all the things you said (client is working, account is correct, etc.) is that when you delete the file first, you see whatever it is you expect after doing the upload? I'm willing to accept that. But I still don't see how you're going to debug this without actually calling the API to see whether the file made it to the server. Commented Sep 7, 2014 at 20:54

1 Answer 1

1

I realize this isn't really an answer, but there's nowhere else to paste this. :-)

In case it helps, here's a transcript of me writing a file, reading it, overwriting that file, and then reading out the new contents. Maybe you can spot the difference between what you're doing and what I'm doing. (Or maybe you can use the same method of calling get_file to verify whether your writes are in fact working.)

1.9.2-p290 :001 > require 'dropbox_sdk'
 => true
1.9.2-p290 :002 > client = DropboxClient.new('<my access token>')
 => #<DropboxClient:0x007ffb0423bfe8 @session=#<DropboxOAuth2Session:0x007ffb0423bf98 @locale=nil, @access_token="<my access token>">, @root="auto">
1.9.2-p290 :003 > client.put_file('hello.txt', 'hello', true)
 => {"rev"=>"a49510f8d89e", "thumb_exists"=>false, "path"=>"/hello.txt", "is_dir"=>false, "client_mtime"=>"Sun, 07 Sep 2014 20:59:24 +0000", "icon"=>"page_white_text", "bytes"=>5, "modified"=>"Sun, 07 Sep 2014 20:59:24 +0000", "size"=>"5 bytes", "root"=>"dropbox", "mime_type"=>"text/plain", "revision"=>42133}
1.9.2-p290 :004 > client.get_file('hello.txt')
 => "hello"
1.9.2-p290 :005 > client.put_file('hello.txt', 'goodbye', true)
 => {"rev"=>"a49610f8d89e", "thumb_exists"=>false, "path"=>"/hello.txt", "is_dir"=>false, "client_mtime"=>"Sun, 07 Sep 2014 20:59:42 +0000", "icon"=>"page_white_text", "bytes"=>7, "modified"=>"Sun, 07 Sep 2014 20:59:42 +0000", "size"=>"7 bytes", "root"=>"dropbox", "mime_type"=>"text/plain", "revision"=>42134}
1.9.2-p290 :006 > client.get_file('hello.txt')
 => "goodbye"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.