2016-01-06 100 views
2

我想将图像选择到图库中,并且想要在保管箱中上传该图像。如何才能做到这一点?如何将图像文件上传到Dropbox?

我试过的Dropbox SDK,但我不知道如何上传所选图像

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

这种方法在DBRestClient.h定义,从DropBox SDK iOS版库文件。但是从上面的方法声明中,需要确定存在于UIImageView中的图像的“fromPath”,以将其上传到我的Dropbox上的帐户。您能否帮助我确定路径,或者就此而言,可以适用哪些工作。

回答

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

Here是如何实现这一目标的教程。这是几个步骤,很难说出你做错了什么,这就是为什么我只包含一个答案的链接。

但基本上

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

我建议你检查教程,因为有一些框架进口和其他的东西,是必需的。