How to rename a photo using the media plugin Cordova

0

I'm developing an application and this application receives some media files (videos, photos and audios) so I'm using the media capture , but when the user takes a photo for example it generates a random name, something like this 145938172015.jpg , would like anyone to see something like that in imagem01.jpg place. Below is my code that I use for image capture.

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');
},
    
asked by anonymous 09.07.2015 / 16:39

1 answer

0

Hello, browsing the Plugin source code we can see that at some point it records the image in memory.

For this it uses getContentResolver().insert (on Android at least), returning an image ID. As your goal is not to create something from scratch in Java to handle it and modify the plugin will require modifications on all platforms we'd better find other options.

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

To know how to handle it is pretty 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.

    
16.07.2015 / 14:53