Your workflow is unique 👨💻 - tell us how you use Dropbox here.
Forum Discussion
Tshaniii
2 years agoHelpful | Level 5
dropbox file download - dbx.filesDownload
var dbx = new Dropbox({ accessToken: dbx_access_token , fetch}); await dbx.filesDownload({ path: dbx_path }).then(async (response) => { console.log("down"); awa...
Tshaniii
2 years agoHelpful | Level 5
I added as
var dbx = new Dropbox({ accessToken: dbx_access_token , fetch});
console.log(document.Folder.name);
await dbx.filesListFolder({ path: `/${document.Folder.name}` })
.then((response) => {
console.log(response.result.entries);
console.log('Files and folders in your Dropbox account:', response);
response.result.entries.forEach((entry) => {
console.log(entry.name, document.title);
if ((entry.name).toString() === (document.title).toString()) {
let file_id = entry.id;
console.log(file_id);
dbx.filesDownload({
path: `${file_id}`
}).then(async (response) => {
console.log("down");
await response.pipe(temporaryFileStream);
}).catch((error) => {
console.log(error);
});
}
console.log(entry.name);
});
})
.catch((error) => {
console.error(error);
});
This code may not be correct as if the folder has subfolders it might not correctly give the entries. So please suggest me how to do this?
TypeError: res.buffer is not a function
at D:\GitHubProjects\docMgtSys\document-management-system\node_modules\dropbox\cjs\src\response.js:67:11
at new Promise (<anonymous>)
at parseDownloadResponse (D:\GitHubProjects\docMgtSys\document-management-system\node_modules\dropbox\cjs\src\response.js:61:10)
at D:\GitHubProjects\docMgtSys\document-management-system\node_modules\dropbox\cjs\src\dropbox.js:146:52
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
I am urgent in completing this feature. Would you be able to please help me in this.
1. App permissions
2. DocFlowController is the app name
3. has 7 folders, History is one of them
4. Inside history there will be subfolders and in them there will be files. sometimes there will be no subfolders but straightaway files.
5. so i want a code to view these files in a editor or somewhere.... i prefer editor becuase there is another feature i implement to open and edit....
please give me a code sample for this. would be a great help! 🙂
Greg-DB
Dropbox Community Moderator
2 years agoTshaniii Calling filesListFolder alone is not guaranteed to give you all of the results. You need to use filesListFolderContinue as well. Check out the documentation for more information. You can set FilesListFolderArg.recursive to true when calling filesListFolder if you want to list nested entries too.
As for the "TypeError: res.buffer is not a function" error, I'm not sure when/how that's occurring. It doesn't seem to reproduce for me. That's presumably related to the link you currently shared as "await response.pipe(temporaryFileStream);" though. If you're trying to access the file data, that would be in "response.result.fileBinary". If you want to save that to the local filesystem, you should refer to the Node.js filesystem documentation for information on how to do so.
- Tshaniii2 years agoHelpful | Level 5var dbx = new Dropbox({ accessToken: dbx_access_token , fetch});console.log(document.Folder.name);await dbx.filesListFolder({ path: `/${document.Folder.name}` }).then(async (response) => {console.log(response.result.entries);console.log('Files and folders in your Dropbox account:', response);response.result.entries.forEach(async (entry) => {console.log(entry.name, document.title);if ((entry.name).toString() === (document.title).toString()) {let file_id = entry.id;console.log(file_id);await dbx.filesDownload({path: `${file_id}`}).then( (response) => {console.log("down");const data = response.result.fileBinary;fs.writeFile(filename, data, (err) => {if (err) throw err;console.log('File saved!');});}).catch((error) => {console.log(error);});}console.log(entry.name);});}).catch((error) => {console.error(error);});return successMessage(res, 'Document viewed successfully');} catch (err) {next(err);}};so this is all i have in my code and the error i get is ,TypeError: res.buffer is not a function
at D:\GitHubProjects\docMgtSys\document-management-system\node_modules\dropbox\cjs\src\response.js:67:11
at new Promise (<anonymous>)
at parseDownloadResponse (D:\GitHubProjects\docMgtSys\document-management-system\node_modules\dropbox\cjs\src\response.js:61:10)
at D:\GitHubProjects\docMgtSys\document-management-system\node_modules\dropbox\cjs\src\dropbox.js:146:52
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async D:\GitHubProjects\docMgtSys\document-management-system\controllers\document-controller.js:170:11when i useI get error: `Error in call to API function "files/list_folder/continue": request body: unknown field 'path'`await dbx.filesListFolderContinue({ path: `/${document.Folder.name}` }),- Greg-DB2 years ago
Dropbox Community Moderator
It's still not clear where the "TypeError: res.buffer is not a function" path is coming from; that doesn't reproduce for me when I run this, so it may be something specific to your environment. I recommend referring to your platform's documentation.
As for the "Error in call to API function "files/list_folder/continue": request body: unknown field 'path'" error, that's because you're supplying a "path" parameter to the filesListFolderContinue method, however that method doesn't accept a "path" parameter. It only accepts a "cursor" parameter. Please refer to the filesListFolder and filesListFolderContinue documentation for information on how to use these methods.
About Dropbox API Support and Feedback
Get help with the Dropbox API from fellow developers and experts.
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!