How to upload a file using Dropbox API iOS v1.0
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.
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
Hello, Marv
I sent my code fragment by e-mail.
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}
David, I sent my test program to you.
good imformation for me!
thank u so much.. and.
plz,send me an example..too ??
Hi Tarbucks,
I sent my Dropbox sample code to you.
hiii it seems great please send me your sample code
Hi Amrit, I sent my Dropbox sample code to you.
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?
Hello Laureano, I sent my Dropbox test project package to you.
Could you please send your sample code to me too, please?
Hi Chris, I sent my test project to you.
I would also appreciate seeing the sample code.
Hi Jim, I sent my test code to you.
would be very happy to have that test program, too! thanks a lot!!!
Hi sebastian,
I sent my Dropbox test project to you.
Please send me a copy of your example. I appreciate your assistance.
Hi Pam, I sent my test project to you.
I also attached my test project in the article.