You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Takes a photo using the camera, or retrieves a photo from the device's
138
-
image gallery. The image is passed to the success callback as a
139
-
Base64-encoded `String`, or as the URI for the image file.
138
+
image gallery. The result is provided in the first parameter of the `successCallback` as a string.
139
+
140
+
As of v8.0.0, the result is formatted as URIs. The scheme will vary depending on settings and platform.
141
+
142
+
|Platform|Destination Type|Format|
143
+
|---|---|---|
144
+
|Android|FILE_URI|An URI scheme such as `file://...` or `content://...`|
145
+
||DATA_URL|Base 64 encoded with the proper data URI header|
146
+
|iOS|FILE_URI|`file://` schemed paths|
147
+
||DATA_URL|Base 64 encoded with the proper data URI header|
148
+
|Browser|FILE_URI|Not supported|
149
+
||DATA_URL|Base 64 encoded with the proper data URI header|
150
+
151
+
v7 and earlier versions, the return format is as follows:
152
+
153
+
|Platform|Destination Type|Format|
154
+
|---|---|---|
155
+
|Android|FILE_URI|Raw file path (unprefixed)|
156
+
||DATA_URL|Base 64 encoded, without the `data:` prefix
157
+
|iOS|FILE_URI|`file://` schemed paths|
158
+
||DATA_URL|Base 64 encoded, without the `data:` prefix
159
+
|Browser|FILE_URI|Not supported|
160
+
||DATA_URL|Base 64 encoded, without the `data:` prefix|
161
+
162
+
For this reason, upgrading to v8 is strongly recommended as it greatly streamlines the return data.
140
163
141
164
The `camera.getPicture` function opens the device's default camera
142
165
application that allows users to snap pictures by default - this behavior occurs,
@@ -149,16 +172,10 @@ that allows users to select an existing image.
149
172
150
173
The return value is sent to the [`cameraSuccess`](#module_camera.onSuccess) callback function, in
151
174
one of the following formats, depending on the specified
152
-
`cameraOptions`:
153
-
154
-
- A `String` containing the Base64-encoded photo image.
155
-
- A `String` representing the image file location on local storage (default).
156
-
157
-
You can do whatever you want with the encoded image or URI, for
158
-
example:
175
+
`cameraOptions`. You can do whatever you want with content:
159
176
160
-
- Render the image in an `<img>`tag, as in the example below
161
-
-Save the data locally (`LocalStorage`, [Lawnchair](http://brianleroux.github.com/lawnchair/), etc.)
177
+
- Render the content in an `<img>`or `<video>` tag
178
+
-Copy the data to a persistent location
162
179
- Post the data to a remote server
163
180
164
181
__NOTE__: Photo resolution on newer devices is quite good. Photos
@@ -167,6 +184,20 @@ quality, even if a `quality` parameter is specified. To avoid common
167
184
memory problems, set `Camera.destinationType` to `FILE_URI` rather
168
185
than `DATA_URL`.
169
186
187
+
#### FILE_URI Usage
188
+
189
+
When `FILE_URI` is used, the returned path is not directly usable. The file path needs to be resolved into
190
+
a DOM-usable URL using the [Cordova File Plugin](https://github.com/apache/cordova-plugin-file).
191
+
192
+
Additionally, the file URIs returned is a temporary read access grant. The OS reserves the right to revoke permission to access the resource, which typically occurs after the app has been closed. For images captured using the camera, the image is stored in a temporary location which can be cleared at any time, usually after the app exits. It's the application's decision to decide how the content should be used depending on their use cases.
193
+
194
+
For persistent access to the content, the resource should be copied to your app's storage container. An example use case is an app allowing an user to select a profile picture from their gallery or camera. The application will need
195
+
consistent access to that resource, so it's not suitable to retain the temporary access path. So the appplication should copy the resource to a persistent location.
196
+
197
+
For use cases that involve temporary use, it is valid and safe to use the temporary file path to display the content. An example of this could be an image editing application, rendering the data into a canvas.
198
+
199
+
__NOTE__: The returned schemes is an implementation detail. Do not assume that it will always be a `file://` URI.
200
+
170
201
__Supported Platforms__
171
202
172
203
- Android
@@ -232,15 +263,22 @@ Callback function that provides the image data.
232
263
233
264
| Param | Type | Description |
234
265
| --- | --- | --- |
235
-
| imageData | <code>string</code> |Base64 encoding of the image data, _or_ the image file URI, depending on [`cameraOptions`](#module_camera.CameraOptions) in effect. |
266
+
| imageData | <code>string</code> |Data URI, _or_ the image file URI, depending on [`cameraOptions`](#module_camera.CameraOptions) in effect. |
@@ -282,7 +320,7 @@ Defines the output format of `Camera.getPicture` call.
282
320
283
321
| Name | Type | Default | Description |
284
322
| --- | --- | --- | --- |
285
-
| DATA_URL | <code>number</code> | <code>0</code> | Return base64 encoded string. DATA_URL can be very memory intensive and cause app crashes or out of memory errors. Use FILE_URI if possible |
323
+
| DATA_URL | <code>number</code> | <code>0</code> | Return data uri. DATA_URL can be very memory intensive and cause app crashes or out of memory errors. Use FILE_URI if possible |
286
324
| FILE_URI | <code>number</code> | <code>1</code> | Return file uri (content://media/external/images/media/2 for Android) |
- Ignores the `encodingType` parameter if the image is unedited (i.e. `quality` is 100, `correctOrientation` is false, and no `targetHeight` or `targetWidth` are specified). The `CAMERA` source will always return the JPEG file given by the native camera and the `PHOTOLIBRARY` and `SAVEDPHOTOALBUM` sources will return the selected file in its existing encoding.
488
536
489
-
#### iOS Quirks
490
-
491
-
- When using `destinationType.FILE_URI`, photos are saved in the application's temporary directory. The contents of the application's temporary directory is deleted when the application ends.
## Sample: Take Pictures, Select Pictures from the Picture Library, and Get Thumbnails <aname="sample"></a>
@@ -639,49 +682,36 @@ function openFilePicker(selection) {
639
682
640
683
## Take a picture and get a FileEntry Object <aname="convert"></a>
641
684
642
-
If you want to do something like copy the image to another location, or upload it somewhere using the FileTransfer plugin, you need to get a FileEntry object for the returned picture. To do that, call `window.resolveLocalFileSystemURL` on the file URI returned by the Camera app. If you need to use a FileEntry object, set the `destinationType` to `Camera.DestinationType.FILE_URI` in your CameraOptions object (this is also the default value).
685
+
If you want to do something like copy the image to another location, or upload it somewhere, an `FileEntry` is needed for the returned picture. To do this, call `window.resolveLocalFileSystemURL` on the file URI returned by the Camera app. If you need to use a FileEntry object, set the `destinationType` to `Camera.DestinationType.FILE_URI` in your CameraOptions object (this is also the default value).
643
686
644
-
>*Note* You need the [File plugin](https://www.npmjs.com/package/cordova-plugin-file) to call `window.resolveLocalFileSystemURL`.
687
+
__NOTE:__ You need the [File plugin](https://www.npmjs.com/package/cordova-plugin-file) to call `window.resolveLocalFileSystemURL`.
645
688
646
689
Here is the call to `window.resolveLocalFileSystemURL`. The image URI is passed to this function from the success callback of `getPicture`. The success handler of `resolveLocalFileSystemURL` receives the FileEntry object.
// If don't get the FileEntry (which may happen when testing
659
-
// on some emulators), copy to a new FileEntry.
660
-
createNewFileEntry(imgUri);
661
-
});
662
-
}
663
-
```
664
-
665
-
In the example shown in the preceding code, you call the app's `createNewFileEntry` function if you don't get a valid FileEntry object. The image URI returned from the Camera app should result in a valid FileEntry, but platform behavior on some emulators may be different for files returned from the file picker.
666
-
667
-
>*Note* To see an example of writing to a FileEntry, see the [File plugin README](https://www.npmjs.com/package/cordova-plugin-file).
668
-
669
-
The code shown here creates a file in your app's cache (in sandboxed storage) named `tempFile.jpeg`. With the new FileEntry object, you can copy the image to the file or do something else like upload it.
0 commit comments