You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.
Forum Discussion
tiwas
4 years agoNew member | Level 2
Need a little help getting started - want to write a simple text file
Hi,
Just found this out of necessity 😉 I need to write a small text file (predefined name, predefined content, no need to append) using either a rest client or http request.
Could someone point me in the direction of information on how to do this without reading the whole API reference? 😉
Thanks!
To upload a small file, you'd use the /2/files/upload endpoint:
https://www.dropbox.com/developers/documentation/http/documentation#files-upload
That's a link to the documentation for the HTTPS endpoints themselves, but we recommend using one of the official SDKs if possible:
https://www.dropbox.com/developers/documentation
Those have corresponding native methods for the HTTPS endpoints.
- Greg-DBDropbox Staff
To upload a small file, you'd use the /2/files/upload endpoint:
https://www.dropbox.com/developers/documentation/http/documentation#files-upload
That's a link to the documentation for the HTTPS endpoints themselves, but we recommend using one of the official SDKs if possible:
https://www.dropbox.com/developers/documentation
Those have corresponding native methods for the HTTPS endpoints.
- tiwasNew member | Level 2
Thanks for that, it's pretty close to what I'm looking for. However, I have one more question.
Say I wanted to create a file in ~/compTest/test.txt, I would access the following path with the following payload?
https://content.dropboxapi.com/2/files/upload
{ "path": "/compTest/test.txt", "mode": { ".tag": "overwrite",
"update": "a1c10ce0dd78"
},
"autorename": false,
"mute": false,
"strict_conflict": false
}Is there a way for me to specify the contents of the file? I would call this from a home automation system, so I don't have anywhere to store local files. The alternative would be to create a template in my dropbox and use the copy_v2 to copy this to the location I need it. It would be a workaround, but not very neat 😉
- Greg-DBDropbox Staff
[Cross-linking for reference: https://stackoverflow.com/questions/66787691/create-file-with-text-with-dropbox-api-rest-or-http ]
Yes, the /2/files/upload endpoint is a "content-upload" style endpoint, so you can supply the file data to upload in the HTTPS request body. You may need to refer to the documentation for whatever HTTPS client you're using for information on how to set the request body.
Also, I notice in the code you posted that you have '".tag": "overwrite"', but then set an 'update' value, which isn't expected. You would only set an 'update' value if you're using '".tag": "update"', there. You can use the API v2 Explorer to help prototype calls like this.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,888 PostsLatest Activity: 24 hours agoIf 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 or Facebook.
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!