Reputation: 978
I want to select image into gallery and that image i want to upload in dropbox.How can i do this?
i tried dropbox SDK but i do not know how to upload selected image
- (void)uploadFile:(NSString*)filename toPath:(NSString*)path fromPath:(NSString *)sourcePath
this method is defined in DBRestClient.h
,a library file from the DropBox SDK
for iOS. But as from the above declaration of the method, the "fromPath" of the image which is present in the UIImageView needs to be ascertained to upload it to my account on dropbox. Can you please help me in how to determine the path, or for that matter, any work around which can be applicable.
Upvotes: 2
Views: 649
Reputation: 26
NSData *data = UIImagePNGRepresentation(imageView.image);
NSString *file = [NSTemporaryDirectory() stringByAppendingPathComponent:@"upload.png"];
[data writeToFile:file atomically:YES];
[DBRestClient uploadFile:@"upload.png" toPath:@"Dropbox/Path" fromPath:file];
Upvotes: 1
Reputation: 38843
Here is a tutorial of how to achieve that. It´s a couple of steps and hard to tell what you´re doing wrong, that´s why I have only included a link for the answer.
But basically
let uploadTextFileAction = UIAlertAction(title: "Upload text file", style: UIAlertActionStyle.Default) { (action) -> Void in
let uploadFilename = "testtext.txt"
let sourcePath = NSBundle.mainBundle().pathForResource("testtext", ofType: "txt")
let destinationPath = "/"
self.dbRestClient.uploadFile(uploadFilename, toPath: destinationPath, withParentRev: nil, fromPath: sourcePath)
}
I recommend you to check the tutorial, since there are some framework imports and other stuff that is required.
Upvotes: 1