简体   繁体   中英

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

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];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM