选择并通过 FTP 传输相机胶卷图像
这是我试图实现的快速流程:
- 用户选择现有的相机胶卷图像或视频。
- 该应用程序将选定的图像通过 FTP 传输到远程 FTP 服务器。
非常简单,至少看起来是这样!
到目前为止,我可以让 UIImagePickerController 允许用户从相机胶卷中选择图像,并可以通过以下方式获取图像的 NSURL:
NSURL *assetURL = [info objectForKey:UIImagePickerControllerReferenceURL];
这会返回类似以下内容:
assets-library://asset/asset.JPG?id=ACE09510-60D8-41EF-BC26-0A0A4D57B21C&ext=JPG
现在,跳到第 2 部分,我可以成功地将文件通过 FTP 传输到使用CFNetwork框架的远程服务器。
这里缺少的链接似乎是将资产库格式的 NSURL (*assetURL) 转换为 NSFileManager 使用的标准文件格式 URL。
如果我使用指向应用程序包中已有的 .jpg 的硬编码文件 URL,我可以成功地将其通过 FTP 传输出去。但是,如果我使用资产库格式的 URL,我会在另一端得到零字节。
我的问题是如何将资产库 URL 转换为常规文件 URL? 我已经看到了如何将相机胶卷图像复制到我的文档目录的示例。然后我想我可以使用该文件 URL 来发送图像。但是,如果我计划发送视频,将一个大文件复制到 Documents 目录只是为了通过 FTP 传输出去并不是很明智的做法。
我确实意识到 FTP 不是首选协议,并且存在漏洞。然而,它是一个现有的 FTP 服务器,并且付钱给我的权力告诉我“如何使用它”。
我显然缺少一两个关于如何实现这一点的概念。提前非常感谢任何能够为我指明正确方向的人。
Here is a quick process flow that I am trying to implement:
- User selects an existing Camera Roll image or video.
- The app FTPs the selected image out to a remote FTP server.
Pretty straight forward, or so it seems!
So far I can get the UIImagePickerController to allow the user to select an image from the Camera Roll and can get a NSURL of the image with:
NSURL *assetURL = [info objectForKey:UIImagePickerControllerReferenceURL];
this returns something like:
assets-library://asset/asset.JPG?id=ACE09510-60D8-41EF-BC26-0A0A4D57B21C&ext=JPG
Now, jumping ahead to part 2, I can successfully FTP a file to a remote server using the CFNetwork framework.
The missing link here seems to be converting the assets-library formatted NSURL (*assetURL) to a standard file format URL that NSFileManager uses.
If I use a hard-coded file URL pointing at a .jpg already in my application bundle I can successfully FTP it out. However, if I use the assets-library formatted URL I get zero bytes at the other end.
My question is just how do I convert the assets-library URL to a regular file URL?
I've seen examples of how to copy a Camera Roll image to my Documents directory. And then I guess I could use that file URL to send the image. However, if I am planning on sending video, it would not be very wise to copy an huge file to the Documents directory just to FTP it out.
I do realize that FTP is not the protocol of choice, and is wrought with holes. However, it is an existing FTP server, and I have been told "thow shalt use it" by the powers that pay me.
I am obviously missing a concept or two on how to implement this. Many thanks ahead of time to anyone who can point me in the right direction.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是,您无法在 iOS 中获得对 Assets 目录的文件级访问权限(这解释了为什么您无法引用照片文件本身),但您仍然应该能够使用 ALAssetLibrary 来创建图像。存储在 URL 中的数据。查看此问题的答案,其中显示如何使用 ALAssetRepresentation 对象创建 UIImage。使用此技术,您应该能够获取发送到 FTP 服务器所需的图像数据。
Unfortunately, you do not get file-level access to the Assets directory in iOS (which explains why you can't reference the photo file itself), but you should still be able to do what you need using the ALAssetLibrary to create an image from the data stored at the URL. Check out the answer to this question, which shows how to create a UIImage using the ALAssetRepresentation object. Using this technique, you should be able to obtain the image data needed to send to the FTP server.