0

I'm attempting to post a large number of records (2000-ish) to Dropbox via the Datastore JS API. I'm getting this error:

POST https://api12.dropbox.com/1/datastores/put_delta 400 (Bad Request)

...and it references: api12.dropbox.com/1/datastores/put_delta:1

That's not a lot of info to use when debugging, but I'm guess it's because I'm over the size limit.

Any ideas how I can fix this or at least debug it further?

Update

I used the XHR inspector in Chrome to get this response:

{"error": 
  {
  "size_limit": "Error: put_delta of delta (size 4138335) exceeds size limit 2097152 bytes",
  "object_type": "delta", 
  "limit": 2097152, 
  "size": 4138335
 }
}
2
  • Is there anything in the body of the response? I believe it should contain more useful information about the error. Commented Dec 3, 2014 at 21:25
  • I looked again and found the response JSON (see above). If I don't know what the size of the POST will be in my app. Is there a way for me to break up the request into chunks? Is there a way to "sync" periodically like there is in the iOS SDK to keep the request size down? Commented Dec 3, 2014 at 23:31

1 Answer 1

1

In the JS SDK, there's an implicit "sync" every time your code yields control back to the browser. So if you write a for loop entering a lot of data, that will all go into a single delta. You can break things up by writing in smaller chunks. For example, something like this (untested, sorry if there's an off-by-one error or the like):

var LIMIT = 100; // how many things to write in a single delta

function writeThings(arrayOfThings) {

    // write up to LIMIT things
    for (var i = 0; i < arrayOfThings.length && i < LIMIT; i++) {
        writeSingleThing(arrayOfThings[i]);
    }

    if (i < arrayOfThings.length) {
        // more to write

        window.setTimeout(function () {
            // after a tick, continue from where we left off
            writeThings(arrayOfThings.slice(i));
        }, 1);
    } else {
        // done writing
    }

}
Sign up to request clarification or add additional context in comments.

4 Comments

This is interesting and helpful, thanks. Is the if/else statement supposed to be inside the for loop so it can reference i?
No, the if/else is where it's supposed to be. i should still be in scope. Why, are you seeing an error?
You're right, it still is in scope (JavaScript is weird). :) I found my real issue. The setTimeout function needs the function to be the first parameter, and the timeout interval to be the second parameter. This is working great for me now. I can upload large datasets without hitting the delta limit. Thank you!
Cool! I updated the answer to match the right use for window.setTimeout.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.