上传使用UIImagePickerController选择的图片

编程入门 行业动态 更新时间:2024-10-16 02:30:19
本文介绍了上传使用UIImagePickerController选择的图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试上传使用UIImagePickerController选择的图片。 UIImagePickerController给出了我可以在视图中显示的UIImage对象,但它没有给出路径(可能是它,我看错了地方)。

I'm trying to upload the picture selected using UIImagePickerController. The UIImagePickerController gives UIImage object that I can display in a view, but it doesn't give a path (may be it does and I'm looking at wrong place).

我正在使用ASIFormDataRequest上传内容,但这需要上传图片的路径。

I'm using ASIFormDataRequest to upload content, but this would need path to the picture to upload it.

有什么建议吗?

谢谢

推荐答案

如果您有UIImage,那么您不需要本地路径来上传图片,你可以使用以下代码上传它。

If you have UIImage with you than you don't need local path for image to upload, you can upload it using following code.

NSData *imgData = UIImagePNGRepresentation(YourUIImageObject); NSURL *url = @"yourURL"; ASIFormDataRequest *currentRequest = [ASIFormDataRequest requestWithURL:url]; [currentRequest setPostFormat:ASIMultipartFormDataPostFormat]; [currentRequest setRequestMethod:@"POST"]; [currentRequest addData:imgData withFileName:@"file" andContentType:@"image/png" forKey:@"yourFileNameOnServer"]; //This would be the file name which is accepting image object on server side e.g. php page accepting file [currentRequest setDelegate:self]; [currentRequest setDidFinishSelector:@selector(uploadImageFinished:)]; [currentRequest setDidFailSelector:@selector(uploadImageFailed:)]; [currentRequest startSynchronous]; -(void)uploadImageFinished:(ASIHTTPRequest*)request { //Your request successfully executed. Handle accordingly. } -(void)uploadImageFailed:(ASIHTTPRequest*)request { //Your request failed to execute. Handle accordingly. }

如有任何疑问,请留言。

Please leave comment in case of any doubt.

希望有所帮助。

更多推荐

上传使用UIImagePickerController选择的图片

本文发布于:2023-06-01 03:18:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/405133.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:上传   图片   UIImagePickerController

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!