Home > iPhone/iPod Touch, Programming > How to upload a file using Dropbox API iOS v1.0

How to upload a file using Dropbox API iOS v1.0

November 5th, 2011 Leave a comment Go to comments

I am going to use Dropbox API to my iOS application. There is no documentation available for Dropbox SDK for iOS. We need to understand how to use it by sample project which is included with SDK, tutorial on the web and SDK header files.

At first I confirmed sample project ‘DBRoulette’ works fine on my environment. Then I started to try ‘tutorial’ on the Dropbox SDK web page. When I try uploadFile API of the tutorial, I got a ‘deprecated’ warning message.

I could understand the new uploadFile API by Changelog and DBRestClient.h. I hope that the tutorial will be revised to use new API in the future.

- (void)uploadFile:(NSString *)filename toPath:(NSString *)path withParentRev:(NSString *)parentRev
    fromPath:(NSString *)sourcePath;

Here is new uploadFile. paraentRev is new parameter. We can put ‘nil’ here. In this case, uploaded file would never over written existing file on the Dropbox server. If same filename exists on the sever, new filename would be modified like ‘test(1).txt’.

If we need to over write existing file on the server, we need to ger parenetRev before issue the uploadFile. Let me show you simple code fragment for this.

Assumes ‘docDir’ has full pathname for the application Document folder and file ‘test.txt’ is already on the Document folder. resClient is initialized as the tutorial also.

- (void)uploadFile1
{
    [[self restClient] loadMetadata:@"/test.txt"];
}

-(void)uploadFile2:(DBMetadata*)meta
{
    NSString *testfile = [docDir stringByAppendingPathComponent:@"test.txt"];
    [[self restClient] uploadFile:@"test.txt" toPath:@"/" withParentRev:meta.rev fromPath:testfile];
}

// DBRestCleintDelegte
- (void)restClient:(DBRestClient*)client loadedMetadata:(DBMetadata*)metadata
{
    [self uploadFile2:metadata];
}

- (void)restClient:(DBRestClient*)client loadMetadataFailedWithError:(NSError*)error
{
    [self uploadFile2:nil];
}

Purpose of the ‘rev’ is managing revvision of the file on the Dropbox. I do not try this yet. But it looks okay for this code to over write current existing file on the Dropbox server.

You can download my test project DBTest.zip. This is a bit old, but it still works, I think.

Categories: iPhone/iPod Touch, Programming Tags:
  1. Marv
    December 27th, 2011 at 08:41 | #1

    Hey dude! Thanks for that! It’s possible, that you can send me an example ? I tried your tutorial but it doesnd work :( Thanks a lot!

    Best regards from germany,
    marv

  2. admin
    December 27th, 2011 at 12:12 | #2

    Hello, Marv
    I sent my code fragment by e-mail.

  3. David
    September 12th, 2012 at 05:33 | #3

    Could I please request your code snippet as well … Getting this error:

    [WARNING] DropboxSDK: error making request to /1/files_put/sandbox/testfile.sqlite – Invalid parent_rev 1

    error=Invalid parent_rev 1}

  4. admin
    September 12th, 2012 at 18:54 | #4

    David, I sent my test program to you.

  5. Tarbucks
    September 26th, 2012 at 11:37 | #5

    good imformation for me!
    thank u so much.. and.
    plz,send me an example..too ?? :)

  6. admin
    September 26th, 2012 at 19:07 | #6

    Hi Tarbucks,
    I sent my Dropbox sample code to you.

  7. Amrit
    December 14th, 2012 at 16:43 | #7

    hiii it seems great please send me your sample code

  8. admin
    December 17th, 2012 at 12:08 | #8

    Hi Amrit, I sent my Dropbox sample code to you.

  9. Laureano
    February 6th, 2013 at 01:10 | #9

    Hey, how are you? I’ve been trying to use your code to update files but it hasn’t worked for me either. Is it possible for you to send me the code too?

  10. admin
    February 6th, 2013 at 11:02 | #10

    Hello Laureano, I sent my Dropbox test project package to you.

  11. Chris
    February 9th, 2013 at 13:44 | #11

    Could you please send your sample code to me too, please?

  12. admin
    February 12th, 2013 at 00:09 | #12

    Hi Chris, I sent my test project to you.

  13. Jim
    March 16th, 2013 at 11:58 | #13

    I would also appreciate seeing the sample code.

  14. admin
    March 16th, 2013 at 18:28 | #14

    Hi Jim, I sent my test code to you.

  15. sebastian
    April 1st, 2013 at 06:52 | #15

    would be very happy to have that test program, too! thanks a lot!!!

  16. admin
    April 3rd, 2013 at 15:01 | #16

    Hi sebastian,
    I sent my Dropbox test project to you.

  17. Pam Davis
    April 12th, 2013 at 18:08 | #17

    Please send me a copy of your example. I appreciate your assistance.

  18. admin
    April 12th, 2013 at 22:02 | #18

    Hi Pam, I sent my test project to you.

    I also attached my test project in the article.

  19. July 31st, 2013 at 18:45 | #19

    Nice pice of code thx ;-)

  20. August 1st, 2013 at 23:54 | #20

    Hi Swat-M,
    You are welcome! I am happy to hear about that.
    I am trying DropBox SyncAPI. It makes our program to get/put files on Dropbox easier.

  1. No trackbacks yet.