Software Archive
Read-only legacy content
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
17060 Discussions

Is there any way to rename a picture taken from the camera ?

Rodrigo_M_1
New Contributor II
1,832 Views

Hi there,

I'm looking for a way to rename a picture taken from the camera. If any one could help me, I'll appreciate that!

// Camera 3rd party plugin website: https://github.com/01org/cordova-plugin-intel-xdk-camera

document.addEventListener("intel.xdk.camera.picture.add",onSuccess);
document.addEventListener("intel.xdk.camera.picture.busy",onSuccess);
document.addEventListener("intel.xdk.camera.picture.cancel",onSuccess);

function capturePhoto() {
  intel.xdk.camera.takePicture(50,false,"jpg");
}

function onSuccess(evt) {

  if (evt.success === true)
  {
    // create image
    var image = document.createElement('img');
    image.src=intel.xdk.camera.getPictureURL(evt.filename);
    image.id=evt.filename;
    //document.body.appendChild(image);
    getPictureList();
  }
  else
  {
    if (evt.message !== undefined)
    {
        alert(evt.message);
    }
    else
    {
        alert("error capturing picture");
    }
  }
}

 

Thanks!

0 Kudos
1 Solution
Dale_S_Intel
Employee
1,832 Views

When you send the file to a webservice, how do you specify the name?  Is it possible to rename there?

 

Dale

 

View solution in original post

0 Kudos
7 Replies
Chris_P_Intel
Employee
1,832 Views

If I'm not mistaken, you'll need the Cordova File Plugin to do that.  

https://github.com/apache/cordova-plugin-file

http://www.html5rocks.com/en/tutorials/file/filesystem/

Hope this helps,

Chris

0 Kudos
Rodrigo_M_1
New Contributor II
1,832 Views

Hi CHRIS Thanks for the tip, but I have tried and no success!

I have imported the plugin with success, but the code givemes a 'NOT_FOUND_ERR' .. Any idea?

Here is the code:

function rename(cwd, src, newName) {
  cwd.getFile(src, {}, function(fileEntry) {
    fileEntry.moveTo(cwd, newName);
  }, errorHandler);
}

window.requestFileSystem(window.TEMPORARY, 1024*1024, function(fs) {
  rename(fs.root, '/images/Arrow.png', 'you.png');
}, errorHandler);


function errorHandler(e) {
  var msg = '';

  switch (e.code) {
    case FileError.QUOTA_EXCEEDED_ERR:
      msg = 'QUOTA_EXCEEDED_ERR';
      break;
    case FileError.NOT_FOUND_ERR:
      msg = 'NOT_FOUND_ERR';
      break;
    case FileError.SECURITY_ERR:
      msg = 'SECURITY_ERR';
      break;
    case FileError.INVALID_MODIFICATION_ERR:
      msg = 'INVALID_MODIFICATION_ERR';
      break;
    case FileError.INVALID_STATE_ERR:
      msg = 'INVALID_STATE_ERR';
      break;
    default:
      msg = 'Unknown Error';
      break;
  };

  alert('Error: ' + msg);
}

 

Thanks!

0 Kudos
PaulF_IntelCorp
Employee
1,832 Views

The filesystem on a mobile device is not like that on your PC or Mac, you cannot manipulate and rename files except where your app has specific permission and access. Where those places are is very limited and OS dependent. If you are trying to rename files that reside within your app's install location that will not work.
 

0 Kudos
Rodrigo_M_1
New Contributor II
1,832 Views

Paul F. (Intel) wrote:

The filesystem on a mobile device is not like that on your PC or Mac, you cannot manipulate and rename files except where your app has specific permission and access. Where those places are is very limited and OS dependent. If you are trying to rename files that reside within your app's install location that will not work.
 

Hi Paul , I appreciate your reply!

Do you know another way to rename the file ?

The point is: I'll send these file to a webservice, but if we have a multiple phones, they are going to send the same name of the file... and I would like to rename it, and add some thing like the device id for example!

Thanks!

0 Kudos
Dale_S_Intel
Employee
1,833 Views

When you send the file to a webservice, how do you specify the name?  Is it possible to rename there?

 

Dale

 

0 Kudos
Gary_H_2
New Contributor I
1,832 Views

If you are using the FileTransfer plugin then specifying the file name the server will use is one of the options.

0 Kudos
Rodrigo_M_1
New Contributor II
1,832 Views

Hi Dale  / Gary, 

I just did this (before read the answers in here) and it works!

I'm using the File Transfer plugin, and I just rename in the transfer process.

So, I'll take this option for now until I figure out how to rename a local file (I'll need this feature later!)

Thank you guys!

 

0 Kudos
Reply