Need to see if your shared folder is taking up space on your dropbox 👨💻? Find out how to check here.
Forum Discussion
littleninja
9 years agoExplorer | Level 3
Creating a syncing folder in the Dropbox Desktop folder with Node JS
I'm developing a desktop (electron) app that integrates with the Dropbox javascript SDK and uses node js to perform tasks on the local machine, allowing an online and offline experience.
All I am doing is programmatically creating a new folder in the Dropbox desktop folder using node js... the problem is that it automatically sets to NOT sync. I need it to sync as default. If I manually create a new folder then it DOES automatically set to sync.
I have copied the extended attributes found on the syncing folders but it still will not set to sync:
So I created 'General Information' through Node js and 'Hello' was created manually. You can see the different symbols.
This is the what I see when I look at the folders permission and extended attributes via the Terminal... they are identical (after creating the folder with Node js I then get the extended attributes of the syncing parent folder and apply these attributes to the newly created folder).
Can anyone help here? I really need to be able to do this for the app to work as it needs to! I guess I just need to know the exact requirements for creating the folder in the first place that would enable it to sync as default like the manually created one - I honestly didn't foresee this being an issue and it's holding me up badly!
I've been in touch with Dropbox Help who were, well, not much help at all!
9 Replies
- Greg-DB9 years ago
Dropbox Community Moderator
[Cross-linking for reference: https://stackoverflow.com/questions/47094600/creating-a-syncing-folder-in-the-dropbox-desktop-folder-with-node-js ]
If you use the JavaScript SDK to create a new folder, that contacts the Dropbox API servers to issue the create folder command. The Dropbox servers then sends down information about the new folder to the desktop client.
If you create the folder manually, you're creating it first on the local filesystem, and then the desktop client syncs that up to the Dropbox servers.
That difference is creating the discrepancy you're seeing in these two cases with respect to the online only status for these two folders.
The Dropbox API doesn't offer an interface for managing online only settings, but I'll pass this along as a feature request. (We also don't officially support/document managing things like this via the extended attributes. Since those aren't documented, they're subject to change, so you shouldn't rely on them.)
You can set the default behavior for online only though, as covered in this help article under "How can I choose a default setting for new content?" (Be sure to expand Mac or Windows first.)
- littleninja9 years agoExplorer | Level 3
Thanks for your reply... I see what you're saying but managing the smart sync settings doesn't solve my problem... I guess what I'm trying to do is manually sync a file or folder from dropbox.com to the local dropbox folder by retrieving the folder/file information and then either creating the folder or downloading the file and saving it in the correct location. Creating a folder manually, like the Hello one, is exactly what I need to be able to do programmatically through node js.
Is there an endpoint in the Dropbox API somewhere that requests a manual sync of a folder or file to the local dropbox folder? That would answer all my problems!!
- Greg-DB9 years ago
Dropbox Community Moderator
No, unfortunately there isn't an API call like that. We'll consider it a feature request, but I can't promise if/when it would be implemented. Sorry I don't have better news for you! - littleninja9 years agoExplorer | Level 3
Surely then you can tell me how creating a folder manually differs from creating one through node js? I can't believe what I'm trying to do isn't achievable?!?!
- Greg-DB9 years ago
Dropbox Community Moderator
The difference is that with the Node JS library, you're communicating with the Dropbox servers directly, so any changes are essentially remote changes that get synced down to the desktop client, respecting the online only setting for the default behavior for new content. (I.e., the folder creation API call would work whether or not the desktop client is installed.)
When creating the folder manually, you're operating on the local filesystem, not directly on Dropbox.
Sorry I don't have better news for you! - littleninja9 years agoExplorer | Level 3
I see what you're saying but I am acting purely on the local filesystem with Node js... the process has absolutely no connection to the dropbox API whatsoever... it is even done when there is not internet connection, so I'm really at a loss as to why a folder created in the local directory by node js differs to one created manually in the local directory... do you see what I'm saying?
- Greg-DB9 years ago
Dropbox Community Moderator
I'm not sure I follow. You originally mentioned "the Dropbox JavaScript SDK", which I took to mean the official Dropbox JavaScript SDK:
https://github.com/dropbox/dropbox-sdk-js
That does use the Dropbox API. That wouldn't work without an Internet connection. Creating the folder manually on the local filsystem (not using the Dropbox SDK) would work without an Internet connection.
If something isn't working as expected, please share the relevant code/output.
- littleninja9 years agoExplorer | Level 3
Ok, this is what I've got...
An electron app that, when online, uses the official Dropbox Javascript SDK to read the files and folders from a Team folder on Dropbox.
Say you lose internet half way through use (this is unlikely I know, but the app has a separate mobile format that will be used primarily out and about in rural areas).... the app can no longer use the dropbox javascript sdk so it switches to reading from the local Dropbox Desktop folder using node js... no internet connection required.
So far so good... I've done all the above successfully without issue.
Now the final step is for the user, when online, to be able to choose which folders they want to be able to see nad browse in the offline version of the app (due to space issues on iPad and the sheer volume of data we're talking about, a default 'sync everything' through the dropbox Desktop app isn't an option). So the app displays the full folder and file structure using the dropbox JS SDK with an option for each to 'make available offline'. When this is selected for a file, no problem... I retrieve the file through the Dropbox JS SDK and write it to the appropriate folder (assuming it exists) in the local Dropbox Desktop folder, using node js. But the user can also choose a folder to make available offline. Currently I have successfully managed to go through the folder, getting all the folders and files it contains, int eh correct structure, using the Dropbox JS SDK, recreate the folders in the LOCAL Dropbox Desktop folder using Node js and writing the files in the way previously described... but here's the problem... These freshly created folders aren't set to sync by default. If I create a new folder manually in the local Dropbox Desktop folder, however, it does!
That's my issue. Why when a folder is created with Node js in the local directory does Dropbox Desktop not treat it exactly as if I'd created it manually?
I hope this makes it a little clearer? I really appreciate your willingness to understand my problem, I really do!!
- Greg-DB9 years ago
Dropbox Community Moderator
I see, thanks for clarifying. (Part of confusion is that the Dropbox JavaScript SDK can actually be used in Node JS in addition to in browser JavaScript, but it sounds like you're not actually referring to that.)
That is, you're actually referring to the difference between these two operations:
1) Creating a folder on the local filesystem by hand, i.e., using the local GUI.
2) Creating a folder on the local filesystem programmatically, using the Node JS filesystem interface (fs.mkdir, presumably).
I thought you were referring to using the API via the Dropbox JavaScript, given you reference to it in the first message, for use in the "online" case.
Unfortunately, since the "offline" operations you're referring to aren't about the API, I'm afraid I can't offer much help, as I only specialize in the Dropbox API (and this is the forum for the API in particular). We don't document/guarantee particular behaviors for the Dropbox desktop client for programmatic use like this.
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!