Camera pictures not displayed in 5.0 - issues with local file URIs [+workaround]

A Arsen Bandurian 3 years ago
0 2 0

Hi, All.

I had an app that took camera pictures (incl RhoSimulator via selecting from gallery). It worked fine in 4.x, the logic was as follows:

>> Ruby controller camera_callback function

if (@params['status'] == "ok") && @params['image_uri']
  pictureURL = Rho::Application.expandDatabaseBlobFilePath(@params['image_uri'])
  WebView.execute_js("update_pic('#{pictureURL}')")

This generates image_uri like db/db-files/Image_12-01-2014_16.28.03_-000.JPG
and pictureURL like C:/MotorolaRhoMobileSuite5.0.2/workspace/AssetInspector/rhosimulator/db/db-files/Image_12-01-2014_16.28.03_-000.JPG

>> JS View

function update_pic(url) {
    $("img#asset_pic").attr('src', url || "/public/images/_img_placeholder.jpg");
}

Which is the same as the official documentation for 4.1 and 5.0 (Rhomobile | Camera)

$("#captured_image").attr("src", Rho.Application.expandDatabaseBlobFilePath(params["imageUri"]));

All this worked nicely until I updated to 5.0.2...

Now, if I just set the SRC of an image to 'C:/MotorolaRhoMobileSuite5.0.2/workspace/AssetInspector/rhosimulator/db/db-files/Image_12-01-2014_16.28.03_-000.JPG'  I get an error
GET c:/MotorolaRhoMobileSuite5.0.2/workspace/AssetInspector/rhosimulator/db/db-files/Image_12-01-2014_15.48.35_-000.JPG  Protocol "c" is unknown

OK, I can imagine that for whatever reason simple file paths are not accepted anymore. So I changed my function to prepend 'file:///' to the URL (also tried explicitly changing this in WebInspector - same result);
Now I'm getting another error:
Not allowed to load local resource: file:///C:/MotorolaRhoMobileSuite5.0.2/workspace/AssetInspector/rhosimulator/db/db-files/Image_12-01-2014_16.28.03_-000.JPG

It appears, that loading files locally is no longer allowed in WebView, and we must load them through web server. For now, I've come up with this workaround, that actually loads files through server:

pictureSRC = pictureURI.sub(Rho::Application.bundleFolder,'')
This transforms C:/MotorolaRhoMobileSuite5.0.2/workspace/AssetInspector/rhosimulator/db/db-files/Image_12-01-2014_16.28.03_-000.JPG
into rhosimulator/db/db-files/Image_12-01-2014_16.28.03_-000.JPG that can be used (with a leading slash '/' ! ) as picture SRC attribute (full path is still required for upload purposes).

How do I get it right? Or is it time to update Rho Documentation/APIs?
Thanks!

Please register or login to post a reply

2 Replies

J Jeffrey Cookle

Hi, just wondering if this was addressed by Motorola/Zebra with loading local images and win32 builds and rhosimulator?

Thank you!

K Kutir Mobility

Arsen,
This issue needs help from Motorola. We will raise this issue with them to get an answer.
Visnupriya R
Kutir Mobility

CONTACT
Can’t find what you’re looking for?