Cordoba Move file using url file

How can I move a file using the URL that I get from the camera?

none successCallback or errorCallback is called by the moveTo function. Can someone tell me what I'm doing wrong and what the possible solution looks like?

function successCallback(entry) {
    console.log("New Path: " + entry.fullPath);
    alert("Success. New Path: " + entry.fullPath);
}

function errorCallback(error) {
    console.log("Error:" + error.code)
    alert(error.code);
}

// fileUri = file:///emu/0/android/cache/something.jpg
function moveFile(fileUri) {
    newFileUri  = cordova.file.dataDirectory + "images/";
    oldFileUri  = fileUri;
    fileExt     = "." + oldFileUri.split('.').pop();

    newFileName = guid("car") + fileExt;

    // move the file to a new directory and rename it
    fileUri.moveTo(cordova.file.dataDirectory, newFileName, successCallback, errorCallback);
}

I am using Cordoba version 4.1.2. Also installed plugin for Cordova files

+4
source share
1 answer

You are trying to call the moveTo function on a String.

moveTO is not a String function, but fileEntry. So, first of all you need to get the Entry file from your URI.

For this, you will call window.resolveLocalFileSystemURL :

function moveFile(fileUri) {
    window.resolveLocalFileSystemURL(
          fileUri,
          function(fileEntry){
                newFileUri  = cordova.file.dataDirectory + "images/";
                oldFileUri  = fileUri;
                fileExt     = "." + oldFileUri.split('.').pop();

                newFileName = guid("car") + fileExt;
                window.resolveLocalFileSystemURL(newFileUri,
                        function(dirEntry) {
                            // move the file to a new directory and rename it
                            fileEntry.moveTo(dirEntry, newFileName, successCallback, errorCallback);
                        },
                        errorCallback);
          },
          errorCallback);
}
+10

Source: https://habr.com/ru/post/1570926/


All Articles