Want to know more about Dash? Check out how Amy uses Dropbox and Dash to make her day easier here!
Forum Discussion
M Arslan
2 months agoExplorer | Level 3
Issue during uploading the image file into the shared folder on dropbox.
I have a shared folder on dropbox account that someone has invited me and give me permission to edit this Folder. Now i want to upload some files by using Python on this folder. I have researched about it and found somehow this solution but i am still encountering the following error during the upload process:
API error: UploadError('path', UploadWriteFailed(reason=WriteError('no_write_permission', None), upload_session_id='pid_upload_session:ABIJK9H7KwTsO3NfedGt3Wv8aCWFwQTwR11SJjV4Yzl3SCg'))
Path error: WriteError('no_write_permission', None)
Below is the code I’m currently using. I would greatly appreciate any guidance or clarification on how to properly upload files to a shared folder under these circumstances, as I’m currently stuck at this point.
import dropbox
from dropbox.files import WriteMode
from dropbox.exceptions import ApiError, AuthError
import os
# Dropbox App Configuration
APP_KEY = 'API Key'
APP_SECRET = ''API Secret key"
REFRESH_TOKEN = '<REFRESH_TOKEN>'
# Shared Folder Configuration
SHARED_FOLDER_ID = '12381081779' # Use the ID we got from verification
LOCAL_FILE_PATH = '1.avif'
def upload_to_shared_folder():
try:
# Initialize Dropbox client
dbx = dropbox.Dropbox(
app_key=APP_KEY,
app_secret=APP_SECRET,
oauth2_refresh_token=REFRESH_TOKEN
)
# Construct proper Dropbox path using namespace syntax
file_name = os.path.basename(LOCAL_FILE_PATH)
dropbox_path = f'ns:{SHARED_FOLDER_ID}/{file_name}'
# Upload file with validated path
with open(LOCAL_FILE_PATH, 'rb') as f:
dbx.files_upload(
f.read(),
dropbox_path,
mode=WriteMode('overwrite'),
autorename=True
)
print(f"Successfully uploaded to shared folder: {dropbox_path}")
except AuthError as e:
print(f"Authentication failed: {e}")
except ApiError as e:
print(f"API error: {e.error}")
if e.error.is_path():
print(f"Path error: {e.error.get_path().reason}")
except Exception as e:
print(f"Unexpected error: {e}")
if __name__ == '__main__':
upload_to_shared_folder()
1 Reply
- DB-Des2 months ago
Dropbox Community Moderator
Hi M Arslan,
Just to clarify, by default, API calls to the Dropbox API operate in the "member folder" of the connected account, not the "team space".
You can configure API calls to operate in the "team space" instead though, in order to interact with files/folders in the team space. To do so, you'll need to set the "Dropbox-API-Path-Root" header. You can find information on how to use this in the Team Files Guide.
Based on the information provided, folder 12381081779 is a team folder, which means you will need to set the "Dropbox-API-Path-Root" header in order to upload files to folder/namespace 12381081779.
Also, just as FYI, your code snippet contained a refresh token value which was removed for your security. We would highly recommend regenerating that refresh token though.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.6,017 PostsLatest Activity: 3 days ago
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!