转换Ios相册路径url与文档目录文件路径相同 [英] Convert Ios Photo Album path url same like as Document directory File-path

查看:205
本文介绍了转换Ios相册路径url与文档目录文件路径相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据我的要求,要访问GCDWebUploader的iOS设备照片应用程序文件的url(而不是作为数据的文件).我想要我的Web服务器的资产库URL.

As per my requirement, want to access iOS device photos app file url (not file as data) for my GCDWebUploader. I want assets library url for my web server.

NSString* documentsPath =[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];

_webServer = [[GCDWebUploader alloc] initWithUploadDirectory: documentsPath];
// this is working and document directory files shown on browser.

_webServer = [[GCDWebUploader alloc] initWithUploadDirectory:assetsUrl];  // this is not working.Nothing shown on browser.   //assetsUrl= assets library url for file from photos app

_webServer.delegate = self;
_webServer.allowHiddenItems = YES;
[_webServer start];

我的网络服务器在PC浏览器上显示所有照片应用程序的图像和视频(如果有文档目录).此功能已使用GCDWebUploader完成.但我找不到资产网址的行为类似于文件路径.

my web-server display all the photos app images and videos on pc browser if document directory.this functionality already done using GCDWebUploader. but I can't find asset url behave like file path.

我不想将照片应用程序文件复制到文档目录中并使用.而是直接从资产库访问.

I don't want to copy the photos app files into document-directory and use.but directly access from assets library.

我希望资产url像文档目录filepath一样工作.请帮我.

I want assets url work same like document directory filepath. please help me for that.

推荐答案

资产网址如下:

assets-library://asset/asset.JPG?id=CD12228F-0E99-4ABD-999D-6A76F54024E7&ext=JPG

这是ALAssetsLibrary的内部URL,在此上下文之外没有任何含义.您不能期望将此URL传递给GCDWebServer并期望服务器对其进行神奇的处理.

This is an internal URL to ALAssetsLibrary which means nothing outside of this context. You can't expect to pass this URL to GCDWebServer and expect the server to magically do something with it.

此外,根据定义,GCDWebServer只能使用HTTP方案,其主机名与您的iPhone/iPad网络名称匹配以及您已实现处理程序的路径来提供URL.

Furthermore, GCDWebServer by definition can only serve URLs with the HTTP scheme, with the hostname matching your iPhone/iPad network name, and with paths for which you have implemented handlers.

例如,如果您为路径/photos/index.html实现了GET处理程序,则使用Web浏览器在http://my-device.local/photos/index.html连接到iPhone/iPad将在GCDWebServer上调用相应的处理程序,然后该处理程序可以返回一些内容(例如HTML网页或图像文件).

For instance if you have implemented a GET handler for the path /photos/index.html, then connecting to your iPhone/iPad using your web browser at http://my-device.local/photos/index.html will call the corresponding handler on GCDWebServer, which then can return some content (like an HTML web page or an image file).

但是从Web浏览器连接到assets-library://asset/asset.JPG并不意味着任何事情,并且会失败.

Connecting however to assets-library://asset/asset.JPG from your web browser doesn't mean anything and will fail.

连接到http://my-device.local/asset.JPG?id=CD12228F-0E99-4ABD-999D-6A76F54024E7&ext=JPG也会失败.

因此,简而言之,要使用GCDWebServer从ALAssetsLibrary提供照片,您可以这样做:

So in a nutshell, to serve photos from ALAssetsLibrary using GCDWebServer, you can do it as such:

  1. 实施默认处理程序以捕获所有GET请求
  2. 为针对/index.htmlGET请求实施处理程序(您必须在默认处理程序之后,将其添加到GCDWebServer实例 )
  1. Implement a default handler to catch all GET requests
  2. Implement a handler for GET requests to /index.html (you must add it to the GCDWebServer instance after the default handler)

/index.html处理程序的实现中,您返回一个HTML网页,该网页列出了ALAssetsLibrary中的照片资产的URL,每个URL都有一个相对的URL链接,例如<a href="/asset.JPG?id=CD12228F-0E99-4ABD-999D-6A76F54024E7&ext=JPG">My photo link</a>(资产网址).

In the implementation of the /index.html handler, you return an HTML web page that lists the URLs of the photo assets from ALAssetsLibrary, each of them having a relative URL link like <a href="/asset.JPG?id=CD12228F-0E99-4ABD-999D-6A76F54024E7&ext=JPG">My photo link</a> (the path portion of the asset URL).

在默认处理程序的实现中,您检索GCDWebServerRequest的路径,并在assets-library://asset前面添加,这将为您提供原始资产URL:assets-library://asset/asset.JPG?id=CD12228F-0E99-4ABD-999D-6A76F54024E7&ext=JPG.使用该URL,您最终可以检索资产数据(即JPEG图像),并使用GCDWebServerDataResponse返回(不要忘记将MIME类型设置为image/jpeg).

In the implementation of the default handler, you retrieve the path of the GCDWebServerRequest, prepend assets-library://asset, and that gives you back the original asset URL: assets-library://asset/asset.JPG?id=CD12228F-0E99-4ABD-999D-6A76F54024E7&ext=JPG. With this URL, you can finally retrieve the asset data, i.e. the JPEG image, and return it using a GCDWebServerDataResponse (don't forget to set the MIME type to image/jpeg).

这篇关于转换Ios相册路径url与文档目录文件路径相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆