I want to figure out how I can upload a file to sharing folder. I have tried following code to upload a file to dropbox. Rather than uploading the file to shared folder "Reports", it uploaded it to my "userfolder/Reports" I tried various options but nothing worked out. I was able to get the shared folder id for the shared folder but there is no shared_path set for the folder. Let me know what else I can do.
import dropbox
DROPBOX_ACCESS_TOKEN = 'TOKEN'
def dropbox_connect():
"""Create a connection to Dropbox."""
try:
dbx = dropbox.Dropbox(DROPBOX_ACCESS_TOKEN)
print('Connected to Dropbox successfully')
except AuthError as e:
print('Error connecting to Dropbox with access token: ' + str(e))
return dbx
dbx = dropbox_connect()
file_path = 'PATHNAME'
# Specify the path to the folder. Here Reports should be a shared folder
destination_path = '/Reports/test.pdf'
# Upload the file to the folder
try:
with open(file_path, 'rb') as file:
response = dbx.files_upload(file.read(), destination_path)
print('File uploaded to shared folder:', response.name)
except FileNotFoundError:
print('File not found:', file_path)
except dropbox.exceptions.ApiError as e:
print('Error uploading file:', e)