2016-01-06 47 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) 
} 

我建議你檢查教程,因爲有一些框架進口和其他的東西,是必需的。