Forum Discussion

Vegepilot's avatar
Vegepilot
Explorer | Level 3
8 years ago

Interpreting iOS upload example

New to iOS development (this will become obvious shortly).

 

Trying to follow these instructions for making an upload style API request:

 

let fileData = "testing data example".data(using: String.Encoding.utf8, allowLossyConversion: false)!

let request = client.files.upload(path: "/test/path/in/Dropbox/account", input: TestData.fileData)

I've managed to upload a sample text file by replacing 'TestData.fileData' with just 'fileData' but the file ends up being called 'account' with no extension.  What was 'TestData' supposed to represent?

 

Also, how do I upload other types of files (mp3, jpeg, etc.)  string.encoding.utf8 is clearly not the answer.

 

Many thanks for helping out the newbie ;-)

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    Apologies, TestData.fileData should indeed just be fileData (per the first line in the example).

     

    Also, the path parameter should be the full path in the Dropbox account where you want to upload the file, including the desired file extension.

     

    So, for example, instead of "/test/path/in/Dropbox/account", if you wanted to upload a file named "Resume.docx" into a folder named "Documents", the path should be "/Documents/Resume.docx".

     

    Uploading files works the same regardless of file type. The example happens to use a string converted to a Data object for simplicity, but you can supply the data using a Data, URL, or InputStream object.

     

    For instance, here's a more advanced example for uploading large files that uploads the file content by reading Data objects from an NSFileHandle:

     

    https://stackoverflow.com/documentation/dropbox-api/409/uploading-a-file/20600/uploading-a-file-from-nsfilehandle-using-upload-sessions-with-every-error-case-h#t=201704191803502783365

    • Vegepilot's avatar
      Vegepilot
      Explorer | Level 3

      Thanks, that makes more sense now.  As for the other files, I'm figuring out URL's so that should work fine.

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.5,950 PostsLatest Activity: 2 days ago
351 Following

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 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!