0

All the Dropbox API SO questions and official documentation I have seen only give examples of uploading files that are external to Dropbox and then downloading Dropbox files to external files using put_file and get_file respectively.

Is there a way to both read and write files exclusively in the Dropbox file system without creating external files?

Community
  • 1
  • 1
Chris Redford
  • 16,982
  • 21
  • 89
  • 109

1 Answers1

1

You can send strings directly to put_file. It doesn't have to be a file object:

# ... insert example code in OP's SO link to get client object

# uploading
s = 'This is a line\n'
s += 'This is another line'
response = client.put_file('/magnum-opus.txt', s)

And files received using get_file can be already accessed directly without creating an external file:

# downloading
f, metadata = client.get_file_and_metadata('/magnum-opus.txt')
for line in f:
    print line
f.close()
Chris Redford
  • 16,982
  • 21
  • 89
  • 109