保存图像路径的位置我正在上传图库的图像,需要将图像路径作为参数传递
- (IBAction)chooseFileBtn:(id)sender {
// For picking image from gallery
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:nil];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
// output image
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
//self.profileImageView.image = chosenImage;
[picker dismissViewControllerAnimated:YES completion:nil];
}
答案 0 :(得分:0)
使用Image Picker ViewController:
,使用以下代码获取从库中选择的图像的路径 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
NSURL *imagePath = [info objectForKey:@"UIImagePickerControllerReferenceURL"];
NSString *imageName = [imagePath lastPathComponent];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *localFilePath = [documentsDirectory stringByAppendingPathComponent:imageName];
NSLog(@"localFilePath.%@",localFilePath);
}
要将此路径作为参数上载到服务器,您可以创建一个multipart / form-data请求,如(POST multipart/form-data with Objective-C) 我希望它能解决你的问题。快乐的编码!