<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Error 429 too_many_requests when uploading multiple files in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Error-429-too-many-requests-when-uploading-multiple-files/m-p/518485#M25331</link>
    <description>&lt;P&gt;Hello all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am used Dropzone to drag and drop upload images and used Javascript Dropbox SDK ( dbx.filesUpload ) to multiple times to upload multiple files.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;But I get "{" error_summary ":" too_many_requests / "," error ": {" reason ": {" .tag ":" too_many_requests "}," retry_after ": 15}}".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have seen and tried many ways but still got the error, the links I have referenced:&lt;/P&gt;
&lt;P&gt;&lt;A title="Performance Guide" href="https://developers.dropbox.com/dbx-performance-guide" target="_blank" rel="noopener"&gt;Performance Guide&lt;/A&gt;&amp;nbsp;&lt;BR /&gt;&lt;A title="too_many_requests when uploading multiple files" href="https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/too-many-requests-when-uploading-multiple-files/td-p/447917" target="_blank" rel="noopener"&gt;too_many_requests when uploading multiple files&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How can I fix this? Below is my code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;var dropzone = new Dropzone('#demo-upload', {
    previewTemplate: document.querySelector('#preview-template').innerHTML,
    parallelUploads: 5,
    thumbnailHeight: 120,
    thumbnailWidth: 120,
    maxFilesize: 500,
    filesizeBase: 1000,
    timeout: 5000,
    acceptedFiles: 'image/*, .dng, .raw'
});

var minSteps = 6,
    maxSteps = 60,
    timeBetweenSteps = 200,
    bytesPerStep = 100000;

dropzone.uploadFiles = function(files) {
    var self = this;

    for (var i = 0; i &amp;lt; files.length; i++) {

        var file = files[i];
        totalSteps = Math.round(Math.min(maxSteps, Math.max(minSteps, file.size / bytesPerStep)));

        for (var step = 0; step &amp;lt; totalSteps; step++) {
            var duration = timeBetweenSteps * (step + 1);
            setTimeout(function(file, totalSteps, step) {
                return function() {
                    file.upload = {
                        progress: 100.0 * (step + 1) / totalSteps,
                        total: file.size,
                        bytesSent: (step + 1) * file.size / totalSteps
                    };

                    self.emit('uploadprogress', file, file.upload.progress, file.upload.bytesSent);
                    if (file.upload.progress == 100) {
                        file.status = Dropzone.SUCCESS;
                        self.emit("success", file, 'success', null);
                        self.emit("complete", file);
                        self.processQueue();
                    }
                };
            }(file, totalSteps, step), duration);
        }

        uploadFile(file);
    }
}

function uploadFile(files) {

    const UPLOAD_FILE_SIZE_LIMIT = 150 * 1024 * 1024; //157,286,400
    var ACCESS_TOKEN = '*********************************';
    var dbx = new Dropbox.Dropbox({ fetch: fetch, accessToken: ACCESS_TOKEN });

    var file = files;

    if (file.size &amp;lt; UPLOAD_FILE_SIZE_LIMIT) { // File is smaller than 150 Mb - use filesUpload API

        dbx.filesUpload({ path: url, contents: file })
            .then(function(response) {

                if (response.status == 200) {
                    dbx.filesGetThumbnail({ path: response.result.path_display, format: "jpeg", size: "w960h640" })
                        .then(function(res) {


                        })
                        .catch(function(error) {

                        });
                }
            })
            .catch(function(error) {

            });
    } else { // File is bigger than 150 Mb - use filesUploadSession* API

        const maxBlob = 8 * 1000 * 1000; // 8Mb - Dropbox JavaScript API suggested max file / chunk size

        var workItems = [];

        var offset = 0;

        while (offset &amp;lt; file.size) {
            var chunkSize = Math.min(maxBlob, file.size - offset);
            workItems.push(file.slice(offset, offset + chunkSize));
            offset += chunkSize;
        }

        const task = workItems.reduce((acc, blob, idx, items) =&amp;gt; {
            if (idx == 0) {
                // Starting multipart upload of file

                return acc.then(function() {
                    return dbx.filesUploadSessionStart({ close: false, contents: blob })
                        .then(response =&amp;gt; response.session_id)
                });
            } else if (idx &amp;lt; items.length - 1) {
                // Append part to the upload session

                return acc.then(function(sessionId) {
                    var cursor = { session_id: sessionId, offset: idx * maxBlob };
                    return dbx.filesUploadSessionAppendV2({ cursor: cursor, close: false, contents: blob }).then(() =&amp;gt; sessionId);
                });
            } else {
                // Last chunk of data, close session

                return acc.then(function(sessionId) {
                    var cursor = { session_id: sessionId, offset: file.size - blob.size };
                    var commit = { path: url, mode: 'add', autorename: true, mute: false };
                    return dbx.filesUploadSessionFinish({ cursor: cursor, commit: commit, contents: blob });
                });
            }
        }, Promise.resolve());

        task.then(function(result) {
            console.log(result);
        }).catch(function(error) {
            console.log(error);
        });

    }
    return false;
}

// Example POST method implementation:
async function postData(url = '', data = {}) {
    // Default options are marked with *
    const response = await fetch(url, {
        method: 'POST', // *GET, POST, PUT, DELETE, etc.
        body: data // body data type must match "Content-Type" header
    });
    return response.json(); // parses JSON response into native JavaScript objects
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!!&lt;/P&gt;</description>
    <pubDate>Thu, 06 May 2021 17:51:28 GMT</pubDate>
    <dc:creator>dangtrung</dc:creator>
    <dc:date>2021-05-06T17:51:28Z</dc:date>
    <item>
      <title>Error 429 too_many_requests when uploading multiple files</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Error-429-too-many-requests-when-uploading-multiple-files/m-p/518485#M25331</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am used Dropzone to drag and drop upload images and used Javascript Dropbox SDK ( dbx.filesUpload ) to multiple times to upload multiple files.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;But I get "{" error_summary ":" too_many_requests / "," error ": {" reason ": {" .tag ":" too_many_requests "}," retry_after ": 15}}".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have seen and tried many ways but still got the error, the links I have referenced:&lt;/P&gt;
&lt;P&gt;&lt;A title="Performance Guide" href="https://developers.dropbox.com/dbx-performance-guide" target="_blank" rel="noopener"&gt;Performance Guide&lt;/A&gt;&amp;nbsp;&lt;BR /&gt;&lt;A title="too_many_requests when uploading multiple files" href="https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/too-many-requests-when-uploading-multiple-files/td-p/447917" target="_blank" rel="noopener"&gt;too_many_requests when uploading multiple files&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How can I fix this? Below is my code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;var dropzone = new Dropzone('#demo-upload', {
    previewTemplate: document.querySelector('#preview-template').innerHTML,
    parallelUploads: 5,
    thumbnailHeight: 120,
    thumbnailWidth: 120,
    maxFilesize: 500,
    filesizeBase: 1000,
    timeout: 5000,
    acceptedFiles: 'image/*, .dng, .raw'
});

var minSteps = 6,
    maxSteps = 60,
    timeBetweenSteps = 200,
    bytesPerStep = 100000;

dropzone.uploadFiles = function(files) {
    var self = this;

    for (var i = 0; i &amp;lt; files.length; i++) {

        var file = files[i];
        totalSteps = Math.round(Math.min(maxSteps, Math.max(minSteps, file.size / bytesPerStep)));

        for (var step = 0; step &amp;lt; totalSteps; step++) {
            var duration = timeBetweenSteps * (step + 1);
            setTimeout(function(file, totalSteps, step) {
                return function() {
                    file.upload = {
                        progress: 100.0 * (step + 1) / totalSteps,
                        total: file.size,
                        bytesSent: (step + 1) * file.size / totalSteps
                    };

                    self.emit('uploadprogress', file, file.upload.progress, file.upload.bytesSent);
                    if (file.upload.progress == 100) {
                        file.status = Dropzone.SUCCESS;
                        self.emit("success", file, 'success', null);
                        self.emit("complete", file);
                        self.processQueue();
                    }
                };
            }(file, totalSteps, step), duration);
        }

        uploadFile(file);
    }
}

function uploadFile(files) {

    const UPLOAD_FILE_SIZE_LIMIT = 150 * 1024 * 1024; //157,286,400
    var ACCESS_TOKEN = '*********************************';
    var dbx = new Dropbox.Dropbox({ fetch: fetch, accessToken: ACCESS_TOKEN });

    var file = files;

    if (file.size &amp;lt; UPLOAD_FILE_SIZE_LIMIT) { // File is smaller than 150 Mb - use filesUpload API

        dbx.filesUpload({ path: url, contents: file })
            .then(function(response) {

                if (response.status == 200) {
                    dbx.filesGetThumbnail({ path: response.result.path_display, format: "jpeg", size: "w960h640" })
                        .then(function(res) {


                        })
                        .catch(function(error) {

                        });
                }
            })
            .catch(function(error) {

            });
    } else { // File is bigger than 150 Mb - use filesUploadSession* API

        const maxBlob = 8 * 1000 * 1000; // 8Mb - Dropbox JavaScript API suggested max file / chunk size

        var workItems = [];

        var offset = 0;

        while (offset &amp;lt; file.size) {
            var chunkSize = Math.min(maxBlob, file.size - offset);
            workItems.push(file.slice(offset, offset + chunkSize));
            offset += chunkSize;
        }

        const task = workItems.reduce((acc, blob, idx, items) =&amp;gt; {
            if (idx == 0) {
                // Starting multipart upload of file

                return acc.then(function() {
                    return dbx.filesUploadSessionStart({ close: false, contents: blob })
                        .then(response =&amp;gt; response.session_id)
                });
            } else if (idx &amp;lt; items.length - 1) {
                // Append part to the upload session

                return acc.then(function(sessionId) {
                    var cursor = { session_id: sessionId, offset: idx * maxBlob };
                    return dbx.filesUploadSessionAppendV2({ cursor: cursor, close: false, contents: blob }).then(() =&amp;gt; sessionId);
                });
            } else {
                // Last chunk of data, close session

                return acc.then(function(sessionId) {
                    var cursor = { session_id: sessionId, offset: file.size - blob.size };
                    var commit = { path: url, mode: 'add', autorename: true, mute: false };
                    return dbx.filesUploadSessionFinish({ cursor: cursor, commit: commit, contents: blob });
                });
            }
        }, Promise.resolve());

        task.then(function(result) {
            console.log(result);
        }).catch(function(error) {
            console.log(error);
        });

    }
    return false;
}

// Example POST method implementation:
async function postData(url = '', data = {}) {
    // Default options are marked with *
    const response = await fetch(url, {
        method: 'POST', // *GET, POST, PUT, DELETE, etc.
        body: data // body data type must match "Content-Type" header
    });
    return response.json(); // parses JSON response into native JavaScript objects
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!!&lt;/P&gt;</description>
      <pubDate>Thu, 06 May 2021 17:51:28 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Error-429-too-many-requests-when-uploading-multiple-files/m-p/518485#M25331</guid>
      <dc:creator>dangtrung</dc:creator>
      <dc:date>2021-05-06T17:51:28Z</dc:date>
    </item>
    <item>
      <title>Re: Error 429 too_many_requests when uploading multiple files</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Error-429-too-many-requests-when-uploading-multiple-files/m-p/518614#M25338</link>
      <description>&lt;P&gt;The Dropbox API does have a rate limiting system that can result in 'too_many_requests' errors like this. The Performance Guide you linked to has guidance on how to best upload multiple files, but in any case you'll want to make sure your code can catch handle these sorts of error responses at any time. When you get one, the best practice is to retry the request, respecting the Retry-After header if given in the response, or using an exponential back-off, if not.&lt;/P&gt;</description>
      <pubDate>Thu, 06 May 2021 15:20:48 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Error-429-too-many-requests-when-uploading-multiple-files/m-p/518614#M25338</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2021-05-06T15:20:48Z</dc:date>
    </item>
    <item>
      <title>Re: Error 429 too_many_requests when uploading multiple files</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Error-429-too-many-requests-when-uploading-multiple-files/m-p/518617#M25340</link>
      <description>&lt;P&gt;Thanks for the reply.&lt;/P&gt;</description>
      <pubDate>Thu, 06 May 2021 15:30:50 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Error-429-too-many-requests-when-uploading-multiple-files/m-p/518617#M25340</guid>
      <dc:creator>dangtrung</dc:creator>
      <dc:date>2021-05-06T15:30:50Z</dc:date>
    </item>
  </channel>
</rss>

