cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to know what we learned at IBC? Check out our learnings on media, remote working and more right here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Re: [Errno 13] Permission Denied; Download Convert to String from Byets; Upload Bytes Not String

[Errno 13] Permission Denied; Download Convert to String from Bytes; Upload Bytes Not String

richard338
New member | Level 2
Go to solution

#Solved!

 

#Python SDK (python package) for Dropbox

#Problem

dbx.files_download_to_file(download_path="/downloads", path="/fileToDownload.txt")

#returns [Errno 13] Permission Denied

 

#Solution

#Omit "/" before directory path name

#download_path="downloads"

dbx.files_download_to_file(download_path="downloads", path="/fileToDownload.txt")

#end Solution section

 

#Download - Convert String to Bytes (search label references:  convert text to bytes; str() to b''; string to b''; str() to b""; string to b"")

#Also; download returns bytes variable to save to file; however, you can decode it, to save the text as a string (python str() variable type), as follows:

metadata, variable_result = dbx.files_download(path='/fileToDownload.txt')

#bytes are returned as variable_result.content

#change them to a string, as follows:

variable_bytes = variable_result.content

variable_string = variable_bytes.decode("utf-8")

f = open("saveTextHere.txt", "x")

f.write(variable_string)

f.close()

 

#Upload - Convert Bytes to String (search label references:  convert text to bytes; str() to bytes; str() to b''; str() to b""; string to b''; string to b"")

t = str("My text to save to upload file. Upload this text to user's Dropbox.com.")

b = t.encode('ascii')

f = '/newFileAtDropbox.txt'

dbx.files_upload(b, f)

#view your uploaded file; file location - Dropbox.com, folder:  Dropbox/Apps/[appFolderName]

1 Accepted Solution

Accepted Solutions

richard338
New member | Level 2
Go to solution
1 Reply 1

richard338
New member | Level 2
Go to solution
Solved, above.
Need more support?