在图库中上传图像时如何将图像路径作为参数发送
How to send image path as a parameter while uploading the image in the Gallery
在哪里保存图片路径我正在为图库上传图片,需要将图片路径作为参数传递
- (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];
}
在使用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)
我希望它能解决您的 issue.Happy 编码问题!
在哪里保存图片路径我正在为图库上传图片,需要将图片路径作为参数传递
- (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];
}
在使用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) 我希望它能解决您的 issue.Happy 编码问题!