iphoneioscordovaphonegap-pluginsalassetslibrary

iOS get photo path from iPhone as f://localhost/...filename.jpg


I'am developing with PhoneGap to iPhone. Trying to FileTransfer.upload(filePath, "http...") a Photo from library.

The process is like this:

First I get a imageURL as base64 string from canvas (HTML5). Then, sending the base64 string to Plugin, written in Objective-C. The Plugin write the file to iPhone photo library, then the plugin return a path to the photo on the iPhone. The Plugin written in Objective-C using the Assets Library to return the photo path. The problem is it return the path like:

assets-library://asset/asset.JPG?id=10000000002&ext=JPG

That path is not accepted by PhoneGap as filePath to FileTransfer.Upload(filePath).

What I need is a way to translate the returning path with the assets-library://... to path that PhoneGap will understands. Or to return a path directly from the Plugin like:

file://localhost/.../filename.jpg

Solution

  • You can't get the actual file URL for the photo. The Photo-Library (as the rest of the OS) is sandboxed. What you need to do is get the representation of the ALAsset object and then call the getBytesMethod of the representation to get the data of the asset. You can then pass that data to phone gap (hopefully).