Cordova Move File using the file url

后端 未结 1 475
天涯浪人
天涯浪人 2021-01-13 19:35

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

neither successCallback nor errorCallback is called by the function moveTo. Can anyone tell me what I am d

相关标签:
1条回答
  • 2021-01-13 20:03

    You're trying to call the function moveTo on a String.

    moveTO is not a function of String but of fileEntry. So first thing you need to do is get a fileEntry from your URI.

    For that you'll 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);
    }
    
    0 讨论(0)
提交回复
热议问题