Oli
Oli

Reputation: 117

Upload a photo using dropbox iOS SDK

How can I upload a photo to DropBox using iOS DropBox SDK. I have tried using the following code:

NSData *datobj = UIImagePNGRepresentation(uploadPhoto.image);
NSString *stringConvertion = [[NSString alloc] initWithData:datobj encoding:NSUTF8StringEncoding];
NSString *filename = stringConvertion;
NSString *destDir = @"/";
[[self restClient] uploadFile:filename toPath:destDir
                   withParentRev:nil fromPath:stringConvertion];

But i get the following response: [WARNING] DropboxSDK: File does not exist ((null))

Upvotes: 0

Views: 1778

Answers (1)

user529758
user529758

Reputation:

You're trying to make a string from the PNG data of the image. Note that

UIImagePNGRepresentation()

doesn't return a file name -- it returns an NSData object whose bytes represent raw PNG data.

Try this:

NSString *tmpPngFile = [NSTemporaryDirectory() stringByAppendingPathComponent:@"Temp.png"];
[UIImagePNGRepresentation(uploadPhoto.image) writeToFile:tmpPngFile atomically:NO];
NSString *destDir = @"/";
[[self restClient] uploadFile:filename toPath:destDir
            withParentRev:nil fromPath:tmpPngName];

Upvotes: 1

Related Questions