<img src="assets-library://〜"> don't work in Cordova6 (Cordova iOS 4.1.1)

810 views
Skip to first unread message

Ryo Kawanobe

unread,
May 14, 2016, 11:39:35 AM5/14/16
to phonegap
Can't display image URI that started with "assets-library://〜".

NG:
 <img src="
   assets-library://asset/asset.JPG?id=FF9A5A50-1954-474B-B9B8-A747EEA573CE&ext=JPG"
>

OK: 
<img src="./img/sample.jpg">

OK: 

Why?
What shoud i do?

i set like below.

in Config.xml
<access origin="*" />
<allow-intent href="*" />


in index.html
<meta http-equiv="Content-Security-Policy" content="default-src 'self' *; connect-src *; img-src *; frame-src *; style-src 'self' 'unsafe-inline' *; script-src 'self' 'unsafe-eval' 'unsafe-inline' *;">


in info.plist
<key>NSAppTransportSecurity</key>
<dict>
 
<key>NSAllowsArbitraryLoads</key>
 
<true/>
</dict>



on iOS9, iPhone6s.

Please help me. 
Thanks.

jcesarmobile

unread,
May 15, 2016, 6:53:03 AM5/15/16
to phonegap
How do you get an assets-library:// image?

Ryo Kawanobe

unread,
May 16, 2016, 1:54:58 AM5/16/16
to phonegap
Thanks, jcesarmobile.

i get the uri from my original plugin that use ALAssetsLibrary.

ALAssetsLibrary *al = [[ALAssetsLibrary alloc] init];
[al writeImageDataToSavedPhotosAlbum:data metadata:metadataAsMutable completionBlock:^(NSURL *assetURL, NSError *error) {
       
if (assetURL) {
            pluginResult
= [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: [assetURL absoluteString]];
       
} else {
            pluginResult
= [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageToErrorObject:2];
       
}
       
[self.commandDelegate sendPluginResult:pluginResult callbackId:callbackID];
 
}];


Regards


2016年5月15日日曜日 19時53分03秒 UTC+9 jcesarmobile:

Kerri Shotts

unread,
May 16, 2016, 10:18:35 AM5/16/16
to phonegap
https://issues.apache.org/jira/browse/CB-9982 might be of interest.

On Monday, May 16, 2016 at 12:54:58 AM UTC-5, Ryo Kawanobe wrote:
...
Message has been deleted

Ryo Kawanobe

unread,
May 17, 2016, 1:10:57 AM5/17/16
to phonegap
Thanks! Kerri.
exactly!

i'll try the other way.

2016年5月16日月曜日 23時18分35秒 UTC+9 Kerri Shotts:

Rob Laverty

unread,
May 19, 2016, 3:36:39 PM5/19/16
to phonegap
I'm curious how you've progressed with this. Right now I'm keeping all images in-memory encoded with Base64. It's causing major memory leaks and I need to figure out how to do this the right way. Thank you!

Ryo Kawanobe

unread,
May 20, 2016, 1:32:01 PM5/20/16
to phonegap
In my case, I got the absolute filepath by saving an image in app. 
This URI start with "/var/〜". 
I didn't use "assets-library://" URI.

    [al writeImageDataToSavedPhotosAlbum:data metadata:metadataAsMutable completionBlock:^(NSURL *assetURL, NSError *error) {
       
if (assetURL) {


           
// NG
           
//pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: [assetURL absoluteString]];

           
// OK
           
NSString* filePath = [weakSelf tempFilePath];
           
// save an image in app.
           
if (![data writeToFile:filePath atomically:YES]) {

                pluginResult
= [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageToErrorObject:2];
           
} else {

                pluginResult
= [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:filePath];

           
}

       
} else {

            pluginResult
= [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageToErrorObject:2];

       
}
       
[self.commandDelegate sendPluginResult:pluginResult callbackId:callbackID];

   
}];

 

2016年5月20日金曜日 4時36分39秒 UTC+9 Rob Laverty:

Jonathan Herdt

unread,
Aug 17, 2016, 4:30:58 PM8/17/16
to phonegap
For me, this worked wonders: In your URL, just replace "assets-library://" with "cdvfile://localhost/assets-library/". Boom, everything works again.

Darth Vader

unread,
May 26, 2017, 2:47:05 PM5/26/17
to phonegap


On Wednesday, August 17, 2016 at 4:30:58 PM UTC-4, Jonathan Herdt wrote:
For me, this worked wonders: In your URL, just replace "assets-library://" with "cdvfile://localhost/assets-library/". Boom, everything works again.

Hey John this might have been a while ago. With assets-library depracated would love to know how to read pictures from asset-library 
Reply all
Reply to author
Forward
0 new messages