cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Are you interested in learning how media industry leaders use Dropbox Replay? Register for our webinar here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Need a little help getting started - want to write a simple text file

Need a little help getting started - want to write a simple text file

tiwas
New member | Level 2
Go to solution

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!

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

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. 

View solution in original post

3 Replies 3

Greg-DB
Dropbox Staff
Go to solution

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. 

tiwas
New member | Level 2
Go to solution

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-DB
Dropbox Staff
Go to solution

[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.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    tiwas New member | Level 2
What do Dropbox user levels mean?