How to rename photo using media capture Cordova plugin

Asked

Viewed 124 times

0

I am developing an application and this application gets some media files(videos, photos and audios) for this I am using the plugin media capture, however when the user takes a photo for example it generates a random name, something like this 145938172015.jpg, I’d like someone to appear in place like this imagem01.jpg. Below is my code that I use to capture the image.

foto: function () {
    navigator.device.capture.captureImage(app.captureFotoSuccess, app.captureFotoError, { limit: 1 });
},
captureFotoSuccess: function (mediaFiles) {
    var i = 0;
    document.getElementById('ArquivosAnexados').value = document.getElementById('ArquivosAnexados').value + mediaFiles[i].fullPath + '; ';
},
captureFotoError: function (error) {
    navigator.notification.alert('Error code: ' + error.code, null, 'Capture Error');
},

1 answer

0

Hello, looking at the plugin source code we can realize that at some point it records the image in memory.

For this he uses getContentResolver().insert (on Android at least), returning an image ID. Since your goal is not to create something from scratch in Java to deal with this and modify the plugin will require modifications on all platforms it is better to find other option.

In this case we can use the Cordova Plugin File, which basically implements HTML5 file API.

To know how to deal with it is quite simple, you can see in this link how to rename a file.

So what you should do is, capture the image with the current plugin, get your ID and location and use the file plugin to rename it to the desired name.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.