<?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 Re: How to upload multiple files using JavaScript SDK? in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-upload-multiple-files-using-JavaScript-SDK/m-p/347164#M19991</link>
    <description>&lt;P&gt;Sorry! it was a typo in my react application because of which files were empty. The issue got resolved.&lt;/P&gt;</description>
    <pubDate>Fri, 31 May 2019 01:31:36 GMT</pubDate>
    <dc:creator>zainulabd786</dc:creator>
    <dc:date>2019-05-31T01:31:36Z</dc:date>
    <item>
      <title>How to upload multiple files using JavaScript SDK?</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-upload-multiple-files-using-JavaScript-SDK/m-p/346967#M19985</link>
      <description>&lt;P&gt;Hi, I am using Javascript SDK to upload multiple files at once. I have a dropbox business account enabled and the folder where I am trying to upload the files is a shared folder.&lt;/P&gt;
&lt;P&gt;I want to upload the files to&lt;/P&gt;
&lt;P&gt;root &amp;gt; Clients &amp;gt; Somefolder&lt;/P&gt;
&lt;P&gt;Clients and Somefolder are the folders created by me.&lt;/P&gt;
&lt;P&gt;Here's my code:&lt;/P&gt;
&lt;PRE&gt;const uploadClientData = async (req, res) =&amp;gt; {
	try {
		const files = req.files
		const { dbxUser } = req;
		const args = {
			contents: files,
			path: '/Clients/Wise',
			mode: 'add',
			autorename: true,
			mute: false,
			strict_conflict: false
		}
		await dbxUser.filesUpload(args);

		res.status(200).json({message: "Uploaded"});
	} catch (error) {
		console.log(error)
		res.status(500).json({
			error: error
        });
	}
}&lt;/PRE&gt;
&lt;P&gt;And here my dropbox Initialization&lt;/P&gt;
&lt;PRE&gt;module.exports = async (req, res, next) =&amp;gt; {
    try {

        let dbxTeam = new DropboxTeam({ fetch: fetch });
        let access_token;

        dbxTeam.setClientId("XXXXXXXXXX");
        dbxTeam.setClientSecret("XXXXXXXXXX");
        
        if(req.body.code){
            access_token = await dbxTeam.getAccessTokenFromCode('http://localhost:3000/authentication', req.body.code);
        } else {
            let team_member_id = req.userData.team_member_id
            access_token = await helpers.getAdminDetails({team_member_id}, "access_token")
            access_token = access_token[0].access_token;
        }
        
        dbxTeam.setAccessToken(access_token);
        let { admin_profile } = await dbxTeam.teamTokenGetAuthenticatedAdmin()

        let dbxUser = new Dropbox({
            accessToken: access_token, 
            selectUser: admin_profile.team_member_id, 
            pathRoot: JSON.stringify({".tag": "root", "root": "5619027360"}) 
        })
        
        req.dbxTeam = dbxTeam,
        req.dbxUser = dbxUser
        next();
    } catch (error) {
        return res.status(500).json({
            message: 'Dropbox Init failed',
            error: error
        });
    }
};&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Jul 2019 09:53:03 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-upload-multiple-files-using-JavaScript-SDK/m-p/346967#M19985</guid>
      <dc:creator>zainulabd786</dc:creator>
      <dc:date>2019-07-16T09:53:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to upload multiple files using JavaScript SDK?</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-upload-multiple-files-using-JavaScript-SDK/m-p/347049#M19986</link>
      <description>&lt;P&gt;The&amp;nbsp;filesUpload method is the right way to upload multiple files, by calling it once per file.&lt;/P&gt;
&lt;P&gt;Can you elaborate on what exactly isn't working for you so we can provide some more specific guidance? For instance, is some part of your code giving you an unexpected error? Please share any error or unexpected output you're getting.&lt;/P&gt;</description>
      <pubDate>Thu, 30 May 2019 14:33:42 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-upload-multiple-files-using-JavaScript-SDK/m-p/347049#M19986</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2019-05-30T14:33:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to upload multiple files using JavaScript SDK?</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-upload-multiple-files-using-JavaScript-SDK/m-p/347074#M19987</link>
      <description>&lt;PRE&gt;const args = {
	contents: files,
	path: '/Clients/Wise',
	mode: 'add',
	autorename: true,
	mute: false,
	strict_conflict: false
}
await dbxUser.filesUpload(args);&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Here the 'files' parameter that I just passed is an array of multiple files.&amp;nbsp;&lt;/P&gt;&lt;P&gt;So my question is, Do I need to loop through the files array and upload files one by one. Because this code doesn't work this way. but if I change the above code to :&lt;/P&gt;&lt;PRE&gt;const args = {
	contents: files[0].buffer,
	path: '/Clients/Wise',
	mode: 'add',
	autorename: true,
	mute: false,
	strict_conflict: false
}&lt;/PRE&gt;&lt;P&gt;This works perfectly. But I don't want to loop through the array. Can't I pass the array to the contents parameter&lt;/P&gt;</description>
      <pubDate>Thu, 30 May 2019 16:06:11 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-upload-multiple-files-using-JavaScript-SDK/m-p/347074#M19987</guid>
      <dc:creator>zainulabd786</dc:creator>
      <dc:date>2019-05-30T16:06:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to upload multiple files using JavaScript SDK?</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-upload-multiple-files-using-JavaScript-SDK/m-p/347083#M19988</link>
      <description>&lt;P&gt;I see, thanks for clarifying. The&amp;nbsp;Dropbox API doesn't offer a way to upload multiple files in one call,&amp;nbsp;but I'll pass this along as a feature request. I can't promise if or when that might be implemented though.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That being the case, you will need to loop through your files and call&amp;nbsp;filesUpload once per file. Apologies I don't have better news for you!&lt;/P&gt;</description>
      <pubDate>Thu, 30 May 2019 16:52:29 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-upload-multiple-files-using-JavaScript-SDK/m-p/347083#M19988</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2019-05-30T16:52:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to upload multiple files using JavaScript SDK?</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-upload-multiple-files-using-JavaScript-SDK/m-p/347143#M19989</link>
      <description>&lt;P&gt;There was a similar question already asked in the Forum at the beginning of 2015. So you replied there the same. Since it has been four years, So I was just wondering if something got updated in the API in these four years. I was trying to reply to that question but couldn't able to do so, nothing happened when I clicked on 'Reply' Button. So I asked another question.&lt;/P&gt;&lt;P&gt;Anyways, Thank you so much for the clarification. let me know when this feature is available.&lt;/P&gt;</description>
      <pubDate>Thu, 30 May 2019 23:02:30 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-upload-multiple-files-using-JavaScript-SDK/m-p/347143#M19989</guid>
      <dc:creator>zainulabd786</dc:creator>
      <dc:date>2019-05-30T23:02:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to upload multiple files using JavaScript SDK?</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-upload-multiple-files-using-JavaScript-SDK/m-p/347158#M19990</link>
      <description>&lt;P&gt;I am having a problem when I am trying to Loop through the files array. Here's my code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;const files = req.files
const clientFolder = req.client_folder
const { dbxUser } = req;
const promises = []
for(const file of files){
	let args = {
		contents: file.buffer,
		path: `${clientFolder}/${file.originalname}`,
		mode: 'add',
		autorename: true,
		mute: false,
		strict_conflict: false
	}
	promises.push(dbxUser.filesUpload(args))
}
Promise.all(promises).then(i =&amp;gt; {
	console.log(i)
	res.status(200).json({message: "Uploaded", status: i});
})&lt;/PRE&gt;&lt;P&gt;dbxUser.filesUpload(args) is an asynchronous function. So I am wondering How can I use this inside the loop.&lt;/P&gt;&lt;P&gt;In my above code I am expecting the function to store the promises in the array, But the promises array is blank in this case&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 31 May 2019 00:38:06 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-upload-multiple-files-using-JavaScript-SDK/m-p/347158#M19990</guid>
      <dc:creator>zainulabd786</dc:creator>
      <dc:date>2019-05-31T00:38:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to upload multiple files using JavaScript SDK?</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-upload-multiple-files-using-JavaScript-SDK/m-p/347164#M19991</link>
      <description>&lt;P&gt;Sorry! it was a typo in my react application because of which files were empty. The issue got resolved.&lt;/P&gt;</description>
      <pubDate>Fri, 31 May 2019 01:31:36 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-upload-multiple-files-using-JavaScript-SDK/m-p/347164#M19991</guid>
      <dc:creator>zainulabd786</dc:creator>
      <dc:date>2019-05-31T01:31:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to upload multiple files using JavaScript SDK?</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-upload-multiple-files-using-JavaScript-SDK/m-p/349131#M20042</link>
      <description>&lt;P&gt;I have around 70 files that I am looping through to upload each file using&amp;nbsp;&lt;SPAN&gt;'filesUpload()'. The problem is this update a few files and then throw the error 429 with a message "too_many_write_operations/."&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Here is my code:&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;const promises = []
for(const file of files){
	const appDir = path.dirname(require.main.filename);
	const f = `${appDir}\\${file.path.replace("/", "\\")}`;
	let args = {
		contents: f,
		path: `${clientFolder}/${file.originalname}`,
		mode: 'add',
		autorename: true,
		mute: false,
		strict_conflict: false
	}
	promises.push(dbxUser.filesUpload(args))
}
		const uploadedData = await Promise.all(promises);&lt;/PRE&gt;</description>
      <pubDate>Mon, 10 Jun 2019 09:58:23 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-upload-multiple-files-using-JavaScript-SDK/m-p/349131#M20042</guid>
      <dc:creator>zainulabd786</dc:creator>
      <dc:date>2019-06-10T09:58:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to upload multiple files using JavaScript SDK?</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-upload-multiple-files-using-JavaScript-SDK/m-p/349248#M20047</link>
      <description>&lt;P&gt;The 429 error that you are getting is due to lock contention. Basically, Promise.all() triggers all requests at the same time and waits for them to resolve before continuing. In this case, all the simultaneous requests are causing lock contention.&lt;/P&gt;
&lt;P&gt;There are two possible solutions:&lt;/P&gt;
&lt;P&gt;1. Execute your requests serially. This may make your script take a little longer, but is probably easier to implement since you've already made so much progress.&lt;/P&gt;
&lt;P&gt;2. Make use of "upload sessions" which is a different endpoint. Take a look at the &lt;A href="https://www.dropbox.com/developers/reference/data-ingress-guide" target="_self"&gt;data ingress guide&lt;/A&gt; for a good explanation. As an added bonus, that guide includes a more detailed explanation of lock contention.&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jun 2019 18:37:54 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-upload-multiple-files-using-JavaScript-SDK/m-p/349248#M20047</guid>
      <dc:creator>TaylorKrusen</dc:creator>
      <dc:date>2019-06-10T18:37:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to upload multiple files using JavaScript SDK?</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-upload-multiple-files-using-JavaScript-SDK/m-p/349336#M20052</link>
      <description>&lt;P&gt;Okay! regarding your second point, According to documentation, "upload sessions" are meant for the files &amp;gt; 150MB, But in my case, The number of files is large but the size of each file is &amp;lt; 150MB.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jun 2019 06:08:41 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-upload-multiple-files-using-JavaScript-SDK/m-p/349336#M20052</guid>
      <dc:creator>zainulabd786</dc:creator>
      <dc:date>2019-06-11T06:08:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to upload multiple files using JavaScript SDK?</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-upload-multiple-files-using-JavaScript-SDK/m-p/349446#M20055</link>
      <description>&lt;P&gt;Upload sessions in general are meant for larger files, but you can also use them for smaller files. That makes sense in particular when you have many files to upload at the same time, because the /2/files/upload_session/finish_batch allows you to commit multiple files at once, without causing lock contention between them. You can find more information on that under "Batch Upload" in the &lt;A href="https://www.dropbox.com/developers/reference/data-ingress-guide" target="_self"&gt;data ingress guide&lt;/A&gt; Taylor linked to.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jun 2019 15:32:03 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-upload-multiple-files-using-JavaScript-SDK/m-p/349446#M20055</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2019-06-11T15:32:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to upload multiple files using JavaScript SDK?</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-upload-multiple-files-using-JavaScript-SDK/m-p/606776#M28130</link>
      <description>&lt;P&gt;Hello guys,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I searched for a long time and found a way to make it esaylly so I hope my cade can help you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const PHOTO_SAVE_FOLDER = 'C:/Users/matth/Desktop/'

/**
* eventName : foler name where are my files to upload on my computer
* folder : dropbox folder name i when to save my files
*/
 const uploadPhotosOnDropbox = async (eventName,folder) =&amp;gt; {
  const errors = [];
  const photosInMyComputer = `${PHOTO_SAVE_FOLDER}${eventName}/${folder}/`
  let photosToUplaod = fs.readdirSync(photosInMyComputer);
  let folderPath = `/Events/${eventName}/${folder}`; // path for dropbox

  // create the folder in dbx,  around with try/catch
  await dbx.filesCreateFolderV2({ path : folderPath, autorename:false}); 

  photosToUplaod.map((photo, idx) =&amp;gt;{
      fs.readFile(`${photosInTheBorne}${photo}`, (err, data) =&amp;gt; {
        setTimeout(()=&amp;gt; {
        let path = `/Events/${eventName}/${folder}/${photo}`;
        const contents = data;
        dbx.filesUpload({ path, contents })
      },idx * 2000);
    });
  });

uploadPhotosOnDropbox('09-08-22-MATT', 'persoFolder');&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 30 Jun 2022 19:26:37 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-upload-multiple-files-using-JavaScript-SDK/m-p/606776#M28130</guid>
      <dc:creator>MatthieuWdi</dc:creator>
      <dc:date>2022-06-30T19:26:37Z</dc:date>
    </item>
  </channel>
</rss>

