如何在ios上上传服务器上的图像?

时间:2014-02-03 11:20:56

标签: ios iphone web-services post http-post

我想从UIImagePickerController上传图片。

我想将我的图片从我的iPad库发布到服务器。

我无法将图像发送到服务器。还有其他选择吗?

我这样做:

-(void)method_OpenImagePickerLibrary{

UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

[self presentViewController:picker animated:YES completion:NULL];
}

-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self dismissViewControllerAnimated:YES completion:nil];
}


-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image=[info objectForKey:UIImagePickerControllerEditedImage];
SelectPickerimageView.image=image;

NSData *imageData = UIImagePNGRepresentation(image);
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
// Here is the file path for the image
filepath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"imagename.png"]];
[imageData writeToFile:filepath options:NSDataWritingAtomic error:nil];

[self dismissModalViewControllerAnimated:YES];
}

-(void)MethodUploadImage{

NSString *ftpUrl=@"ftp://yourftp Url";
NSString *strPortNumber=@"port Number";
NSString *strurlUpload=[NSString stringWithFormat:@"%@:%@",ftpUrl,strPortNumber];

NSString *getfilePath = filepath;
SCRFTPRequest *ftpRequest = [[SCRFTPRequest alloc] initWithURL:[NSURL URLWithString:strurlUpload] toUploadFile:getfilePath];
ftpRequest.username = @"Username";
ftpRequest.password = @"password";
ftpRequest.delegate = self;

/*  

ftpRequest.didFinishSelector = @selector(uploadFinished:);
ftpRequest.didFailSelector = @selector(uploadFailed:);
ftpRequest.willStartSelector = @selector(uploadWillStart:);
ftpRequest.didChangeStatusSelector = @selector(requestStatusChanged:);
ftpRequest.bytesWrittenSelector = @selector(uploadBytesWritten:);*/

[ftpRequest startRequest];
}

这些评论的行给了我错误

  • 错误1 :未声明的选择器
  • 错误2 :属性 didFinishSelector,didFailSelector,willStartSelector,didChangeStatusSelector,bytesWrittenSelector 在SCRFtprequest委托上找不到

非常欢迎任何想法或建议。

1 个答案:

答案 0 :(得分:0)

尝试使用AFNetworking。它一定会让你的生活更轻松。