We Want to Hear From You! What Do You Want to See on the Community? Tell us here!
Forum Discussion
prrvchr
9 months agoExplorer | Level 4
I can no longer upload files
Hi all,
For some time now I have not been able to upload my files via the HTTP API.
The file/upload or file/get_temporary_upload_link gives me a 404 error even though it worked perfectly until now.
If I do CURL tests then everything works perfectly, so I suspect an unsupported header. Here is the list of headers on my HTTP request (I use python/requests to do this):
Headers: {'User-Agent': 'python-requests/2.25.1', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Content-Type': 'application/octet-stream', 'Dropbox-API-Arg': '{"mode":"overwrite","path":"/Sans nom 1.odt","autorename":false,"mute":false,"strict_conflict":false}', 'Content-Length': '473722', 'Authorization': 'Bearer sl.B_3Hk1dv...'}
I'll try adding these headers to CURL to see if that's where it comes from, but I'm interested in any good information.
Thanks.
5 Replies
- prrvchr9 months agoExplorer | Level 4
Ok the CURL header that seems to be no longer supported is:
--header "Accept-Encoding: gzip, deflate" \
How is this possible?
- Greg-DB9 months ago
Dropbox Community Moderator
I just gave this a try myself, but I'm not getting back a 404 error when I use that header. Can you share the full request and response for this issue so we can take a look? If you're using curl, use the -v option to enable verbose mode. Please redact your access token though. Thanks in advance!
- prrvchr9 months agoExplorer | Level 4
Hi Greg,
No, it doesn't come from the headers, sorry.
I can get this Curl query to work correctly:
curl -X POST https://content.dropboxapi.com/2/files/upload \ --header "Authorization: Bearer sl.B_2..." \ --header "Dropbox-API-Arg: {\"autorename\":false,\"mode\":\"overwrite\",\"mute\":false,\"path\":\"/Test Dropbox.odt\",\"strict_conflict\":false}" \ --header "User-Agent: python-requests/2.25.1" \ --header "Accept-Encoding: gzip, deflate" \ --header "Accept: */*" \ --header "Connection: keep-alive" \ --header "Content-Type: application/octet-stream" \ --write-out "%{http_code}\n" \ --data-binary "@/home/prrvchr/Test Dropbox.odt"
On the other hand, if I use Python/Requests instead of Curl, it gives me a 404:
import requests url = 'https://content.dropboxapi.com/2/files/upload' headers = {'Content-Type': 'application/octet-stream', 'Dropbox-API-Arg': '{"autorename": false, "mode": "overwrite", "mute": false, "path": "/Test Dropbox.odt", "strict_conflict": false}', 'Authorization': 'Bearer sl.B_2...'} data = open('/home/prrvchr/Test Dropbox.odt', 'rb') response = requests.put(url, headers=headers, data=data) print("Status Code: %s" % response.status_code) response.close() data.close()
I don't see why...
- Greg-DB9 months ago
Dropbox Community Moderator
Thanks for following up and sharing that. In your Python code, you're using the "PUT" method, via the ".put" call, however the /2/files/upload endpoint expects a "POST". That would be ".post" in the requests library.
- prrvchr9 months agoExplorer | Level 4
Thanks Greg for finding my mistakes...
But this code that you just corrected was only created to test the file/get_temporary_upload_link command which has stopped working for some time.
And I just found what was preventing it from working, it is apparently the temporary upload link which no longer supports an Authorization headers which was there by mistake.
Here is an example of code that worked and no longer works, it now returns a status code 500:
import requests url = 'https://api.dropboxapi.com/2/files/get_temporary_upload_link' token = 'Bearer sl.B_...' headers = {'Authorization': token} json = {'commit_info': {'path': '/Test Dropbox.odt', 'mode': 'overwrite'}, 'duration': 3600} response = requests.post(url, headers=headers, json=json) if not response.ok: print("Request on Url: %s give Status Code: %s" % (url, response.status_code)) response.close() else: url = response.json().get('link') response.close() headers = {'Content-Type': 'application/octet-stream', 'Authorization': token} data = open('/home/prrvchr/Test Dropbox.odt', 'rb') response = requests.post(url, headers=headers, data=data) print("Request on Url: %s give Status Code: %s" % (url, response.status_code)) response.close() data.close()
Anyway, all these problems were caused by a mistake in my code and now it is fixed.
Thanks for your help and I think we can close.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.6,036 PostsLatest Activity: 9 months 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!