我正在使用IOS应用程序,我从我的iPhone模拟器中选择照片,我想在DropBox上传这些照片,但我无法做到这一点。我在上传方法中没有得到正确的参数。
这是我从我的控制器发送所选照片的代码。此代码将我从模拟器中选择的图像发送到控制器,在该控制器中我将用于上载图片的代码写入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:image方法用于上传图片
-(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 :(得分:0)
有一个iOS SDK,它提供API以通过iOS应用程序与投递箱进行交互 以下是dropbox开发人员网站上提供的教程。
https://www.dropbox.com/developers/core/start/ios
以下是您需要查看的操作。
答案 1 :(得分:0)
IN .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];
这里的文件名是文件的名称,localpath是文件的位置。 希望这能帮到你!!!