Need Help With Put For Dropbox Rest Api

Hey Rob,

I finally got the whole Dropbox thing to work.  I now have a nice little app that will allow me to authorize Dropbox access and then grab account info or download a text file.

I’d like to take it up a notch and see if I can upload a file.  But it seems like I might have to use PUT (or POST) for that.  The only thing is I’m not sure how to tell the network.request PUT which file I’d like to upload.  In the API docs, I can see that you can put text in the body of the POST, but I’m not sure how to specify a file (which might be binary, like a JPG).

Any thoughts would be greatly appreciated.

When I get my Dropbox sample code polished, I’ll post on github and make an entry in the Corona Code Exchange.

Hi there,

The “Networking 2.0” version of network.request() allows you to specify a filename as one of the parameters in the params table: http://docs.coronalabs.com/daily/api/library/network/request.html.  Specifically, for params.body, instead of providing text, you provide a table with a field called filename specifying the file name, and a field called baseDirectory specifying the directory where the file is located.

There’s also a convenience method called network.upload() which you can use, if it’s more convenient: http://docs.coronalabs.com/daily/api/library/network/upload.html.  Binary data shouldn’t be a problem, as the APIs let you specify if your data is binary.

Hope this helps.

  • Andrew

Thank you for the wonderful reply!  I am using the latest daily build specifically because I wanted all the wonderful new Network 2.0 functionality.  I just didn’t know that there were separate API docs for daily builds.  This is great news.  Thank you so much.  

It’s more like Christmas than Easter right now!  Yay!

Just updated my Dropbox sample code in the Corona SDK Code Exchange.   See here for details:

http://developer.coronalabs.com/code/dropbox-rest-sample-code

Hi there,

The “Networking 2.0” version of network.request() allows you to specify a filename as one of the parameters in the params table: http://docs.coronalabs.com/daily/api/library/network/request.html.  Specifically, for params.body, instead of providing text, you provide a table with a field called filename specifying the file name, and a field called baseDirectory specifying the directory where the file is located.

There’s also a convenience method called network.upload() which you can use, if it’s more convenient: http://docs.coronalabs.com/daily/api/library/network/upload.html.  Binary data shouldn’t be a problem, as the APIs let you specify if your data is binary.

Hope this helps.

  • Andrew

Thank you for the wonderful reply!  I am using the latest daily build specifically because I wanted all the wonderful new Network 2.0 functionality.  I just didn’t know that there were separate API docs for daily builds.  This is great news.  Thank you so much.  

It’s more like Christmas than Easter right now!  Yay!

Just updated my Dropbox sample code in the Corona SDK Code Exchange.   See here for details:

http://developer.coronalabs.com/code/dropbox-rest-sample-code