2014-05-02 70 views
0

我正在使用IOS應用程序,在該應用程序中我從iPhone模擬器中選擇照片,並且想要將這些照片上傳到DropBox,但我無法做到這一點。我在上傳方法中沒有得到正確的參數。如何從iOS應用程序在DropBox上上傳圖片

這是我的代碼從我的控制器發送選定的圖片。此代碼將發送這是我從我的模擬器選擇了對中,我寫的代碼上傳圖片到保管箱控制器的圖像:

// UIImage *image; 
// NSMutableArray *images 
// @property (nonatomic, copy) NSArray *chosenImages; 

for (NSDictionary *dict in info) 
{ 
    image = [dict objectForKey:UIImagePickerControllerOriginalImage]; 

    [images addObject:image]; 

    imageview = [[UIImageView alloc] initWithImage:image]; 

    [imageview setContentMode:UIViewContentModeScaleAspectFit]; 

    imageview.frame = workingFrame; 

    self.chosenImages = images; 

    RootViewController *rvc=[[RootViewController alloc]init]; 

    [rvc _startUpload:image]; 

    [self.navigationController pushViewController:rvc animated:YES]; 
} 

現在在我的RootViewController的我寫的代碼在這種方法上傳圖片:_startUpload:圖像法用於上傳圖片

-(void)_startUpload:image 
{ 
    NSString *fileName = @"myImage.png"; 

    NSString *tempDir = NSTemporaryDirectory(); 

    NSString *imagePath = [tempDir stringByAppendingPathComponent:fileName]; 

    NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(self.loadQRCodeImage.image)]; 

    [imageData writeToFile:imagePath atomically:YES]; 

    [self.restClient uploadFile:fileName toPath:dropBoxFolder fromPath:imagePath]; 
} 

我沒有收到我的Dropbox的中圖片,請幫助我,我在做什麼錯了,這路我真正用於上傳圖片。請幫幫我。

在此先感謝。

+0

什麼是dropBoxFolder? –

+0

https://www.dropbox.com/developers/sync/start/ios –

回答

0

在.h文件中: -

@interface UploadOptionViewController : UIViewController<UIImagePickerControllerDelegate,DBRestClientDelegate,UINavigationControllerDelegate> 
{ 
DBRestClient *restClient; 
NSString *file; 
} 
-(IBAction)photoLibrary:(id)sender; 
@property (nonatomic,retain) NSString *file; 
@property(retain,nonatomic) DBRestClient *restClient; 
@end 

在.m文件: -

- (DBRestClient *)restClient { 
if (!restClient) { 
    restClient = [[DBRestClient alloc] initWithSession:[DBSession sharedSession]]; 
    restClient.delegate = self; 
} 
return restClient; 
} 

//-------------Upload file from dropbox -------------------------------------------- 

- (void)restClient:(DBRestClient*)client uploadedFile:(NSString*)destPath 
      from:(NSString*)srcPath metadata:(DBMetadata*)metadata { 
[presenter hideHud]; 
NSLog(@"File uploaded successfully to path: %@", metadata.path); 
[[[[UIAlertView alloc] 
    initWithTitle:@"File Uplaod" message:@"File uploaded successfully" 
    delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] 
    autorelease] 
show]; 
} 

- (void)restClient:(DBRestClient*)client uploadFileFailedWithError:(NSError*)error { 
[presenter hideHud]; 
NSLog(@"File upload failed with error - %@", error); 
[[[[UIAlertView alloc] 
    initWithTitle:@"File Upload" message:@"File upload failed" 
    delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] 
    autorelease] 
show]; 
} 

並號召之下酌情

NSString *localPath = [[NSBundle mainBundle] pathForResource:@"Info" ofType:@"plist"]; 
NSString *filename = @"Info.plist"; 
NSString *destDir = @"/"; 
[[self restClient] uploadFile:filename toPath:destDir 
       withParentRev:nil fromPath:localPath]; 

這裏的文件名是名稱 文件的本地路徑是文件被刪除的地方。 希望這可以幫助你!

+0

我不會將圖像從DropBox上傳到我的應用程序。我正在上傳圖像到我的iPhone模擬器的DropBox。請告訴我上傳的方法在保管箱? – Rausi

+0

@Rausi我編輯了答案,現在檢查它! –

+0

謝謝你的信息。當我嘗試捕捉圖像路徑,然後發送到本地路徑,我得到錯誤,數組無法給路徑。我沒有得到我選擇的圖像的本地路徑。所以plz幫助我。 – Rausi

相關問題