We’re Still Here to Help (Even Over the Holidays!) - find out more here.
Forum Discussion
ijunaid8989
7 years agoExplorer | Level 3
too many write operations when uploading files
I am using Elixir wrapper to DropboxAPI to upload files, which is doing simple upload using `files/upload` route. def upload(client, path, file, mode \\ "add", autorename \\ true, mute \\ false) d...
ijunaid8989
7 years agoExplorer | Level 3
Okay thanks now,
on upload_session/start and then doing upload_session/finish
my file is getting uploaded.
the file was of 37 kbs. which I set in offset in upload_session/finish, but
how upload_session/finish_batch can over all the present sessions? when it only takes one session id? and one one file name?
I can now upload the file to my account using only
upload_session/start and upload_session/finish
would that be enough ? for uploading multiple files at once? to dropbox?
I am actually in a loop which being spawned and sending files to dropbox account.
Now I only need to so session start and in the finish add the file size and that it? would that stop sending me too many write operations message?
ijunaid8989
7 years agoExplorer | Level 3
and If I can the append_v2 with close true, it gives me error as
double the offset, it should be, file as 37KBs and it gives an error as offset should be 74
- Greg-DB7 years ago
Dropbox Community Moderator
If you want to commit multiple file uploads at once, and avoid the you should use /2/files/upload_session/finish_batch. That endpoint does not only take a single file name/upload session ID. Its UploadSessionFinishBatchArg.entries parameter takes a list of multiple UploadSessionFinishArg. You can find information on that in the documentation here:
It says "List of (UploadSessionFinishArg, max_items=1000)", indicating that you can supply up to 1000 per call. Each UploadSessionFinishArg should contain the information for a single file and upload session.
When appending data to an upload session, you shouldn't repeatedly send the same data if it's already been successfully sent.
- ijunaid89897 years agoExplorer | Level 3
When I am going to need this append option anyways?
you mean if the file is bigger, I first send some of its kbs and then some of the others?
In case I have a 2MB file? Can I send it once in the first upload session start request. and then Should I still need to do the append? or not?
- ijunaid89897 years agoExplorer | Level 3
Also I can send data only through upload session start and finish..
Finish batch never worked for me to upload all data at once.
- Greg-DB7 years ago
Dropbox Community Moderator
Each of the /start, /append, and /finish endpoints, but not /finish_batch, can accept file data.
You would need to use /append if there is more data than you can send in the /start and /finish requests.
Upload sessions work by having you send only a portion of the file's data per request.
Exactly how much data you send per request is up to you. For example, a maximum of 8 MB per request is reasonable, but it can vary by use case. So, if you were using a maximum of 8 MB per request, and the file is only 2 MB, you would only need a single /start request to send all of the file data (and wouldn't need to call /append for that particular file). You could then use /finish without sending any more data to commit that file, or use /finish_batch to commit that file (as well as others).
- ijunaid89897 years agoExplorer | Level 3
Okay thanks for all your help and replies, right now what I am doing is:
client = ElixirDropbox.Client.new(System.get_env["DROP_BOX_TOKEN"]) {:ok, file_size} = get_file_size(image_path) %{"session_id" => session_id} = ElixirDropbox.Files.UploadSession.start(client, false, image_path) ElixirDropbox.Files.UploadSession.finish(client, session_id, upload_image_path, image_path, file_size) |> handle_upload_responseI still got one error as
"error_summary\": \"too_many_write_operations/\", \"error\": {\"reason\": {\".tag\": \"too_many_write_operations\"and 5 errors are API timed out.
I have no idea why still there is too many write operations error? where as I am right now first starting the session, then finishing it in a proper way?
but these requests almost goes in parallel, should I need to change something as well? more.. - Greg-DB7 years ago
Dropbox Community Moderator
In this code I see you're using the 'finish' method, presumably once per file, to finish the uploads. If you send off multiple of these at the same time, you will cause lock contention.
You should use a single 'finish_batch' to finish multiple file uploads in a single call to avoid this. (Or, only send the multiple 'finish' calls one at a time.)
- ijunaid89897 years agoExplorer | Level 3
I uploaded using session start and I got an session_id.
AAAAAAAb0vwx3ypjoH836Q
and then instead of doing append I just finished the batch of this file
curl -X POST https://api.dropboxapi.com/2/files/upload_session/finish_batch \ --header "Authorization: Bearer -SC69zip6zi9bwHgqhYHNYQbrpZ5C7G" \ --header "Content-Type: application/json" \ --data "{\"entries\": [{\"cursor\": {\"session_id\": \"AAAAAAAb0vwx3ypjoH836Q\",\"offset\": 34520},\"commit\": {\"path\": \"/REGULAR/licence\",\"mode\": \"add\",\"autorename\": true,\"mute\": false,\"strict_conflict\": false}}]}"This gave me results as
{".tag": "async_job_id", "async_job_id": "dbjid:AACg_hehcOljTPYxh6wQhigGQhtc3-eCFneDKK--vzA5V9wBLNi74iNeNqWUQDFOnx1_k-sViaZJpJvXRG0UTlLw"}and whereas on normal session start and finish I just get the file uploaded moreover when I check batch as
curl -X POST https://api.dropboxapi.com/2/files/upload_session/finish_batch/check \ > --header "Authorization: Bearer -SC69zip6zi9bwHgqhYHNYQbrpZ5C7G" \ > --header "Content-Type: application/json" \ > --data "{\"async_job_id\": \"dbjid:AACg_hehcOljTPYxh6wQhigGQhtc3-eCFneDKK--vzA5V9wBLNi74iNeNqWUQDFOnx1_k-sViaZJpJvXRG0UTlLw\"}"it returns as
{".tag": "complete", "entries": [{".tag": "failure", "failure": {".tag": "lookup_failed", "lookup_failed": {".tag": "not_closed"}}}]}So now where I am wrong? the same file is getting uploaded through session start and finish but giving the error in this way?
- Greg-DB7 years ago
Dropbox Community Moderator
ijunaid8989 All of the upload sessions that you wish to finish using /finish_batch need to be "closed" before you call /finish_batch. That message is indicating that the upload session was not closed.
You should close the upload session with the last call you make to upload the final data for that upload session, whether that's on /start or /append, using the "close" parameter.
- ijunaid89897 years agoExplorer | Level 3
Thanks for all your replies and I have fixed this issue, my only question is right now, what could be the reason for timeouts from dropbox api?
I have timeout errors a few, while upload session start.
- Greg-DB7 years ago
Dropbox Community Moderator
Can you share the code and error output you're getting for these timeouts so we can take a look? Thanks!
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
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, Facebook or Instagram.
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!