简体   繁体   English

Cordova文件传输映像未将文件上传到服务器

[英]Cordova file transfer image is not uploading the file to server

Please help me to resolve this issue, am try to solve this from last week. 请帮助我解决此问题,请尝试从上周开始解决此问题。 Using cordova file transfer plugins am try to upload my image to production server however am getting error code 1. 使用cordova文件传输插件尝试将我的图像上传到生产服务器,但是却收到错误代码1。

i checked source and target path both are accessible. 我检查了源路径和目标路径都可以访问。 Please find my cordova setup versions. 请找到我的cordova安装版本。

Cordova -> 7.1.0, Phonegap -> 7.1.1, cordova-plugin-file-transfer -> spec=1.7.1 Cordova- > 7.1.0, Phonegap- > 7.1.1, cordova- 插件文件传输 -> spec = 1.7.1

Code: 码:

 function staticpathu_upload() { var fileURL = 'https://example.com/Al_2_1518090802.jpg'; var uri = encodeURI('https://example.com/dummy.php'); var options = new FileUploadOptions(); options.fileKey = "file"; options.fileName = fileURL.substr(fileURL.lastIndexOf('/')+1); options.mimeType = "image/jpeg"; var ft = new FileTransfer(); ft.upload(fileURL, uri, onSuccess, onError, options); function onSuccess(r) { console.log("Code = " + r.responseCode); console.log("Response = " + r.response); console.log("Sent = " + r.bytesSent); } function onError(error) { console.log(error); alert("An error has occurred: Code = " + error.code); console.log("upload error source " + error.source); console.log("upload error target " + error.target); } } 

Error: 错误:

FileTransferError {
   code: 1, 
   source: "https://example.com/Al_2_1518090802.jpg", 
   target: "https://example.com/dummy.php", 
   http_status: null, 
   body: null,
}

fileUrl must be a fileUrl必须是

Filesystem URL representing the file on the device or a data URI. 表示设备上的文件或数据URI的文件系统URL。 For backwards compatibility, this can also be the full path of the file on the device. 为了向后兼容,这也可以是设备上文件的完整路径。 (See Backwards Compatibility Notes below) (请参阅下面的向后兼容性说明)

See the docs 查看文件

This is propably the reason why a FileTransferError.FILE_NOT_FOUND_ERR (error code 1) is thrown. 这可能是抛出FileTransferError.FILE_NOT_FOUND_ERR (错误代码1)的原因。

This issue with ServerUrl, its not allowing me to post the image to server. ServerUrl的此问题,不允许我将图像发布到服务器。 I have created dummy.php on server root folder and execute from below code its working fine. 我已经在服务器根文件夹上创建了dummy.php,并从下面的代码执行其工作正常。 It won't work from desktop we have check in mobiles or emulators only. 它仅在移动设备或仿真器中无法在台式机上运行。

function uploadphoto(){ 
    navigator.camera.getPicture(uponSuccess, uponFail, { quality: 50,
      sourceType: Camera.PictureSourceType.PHOTOLIBRARY, 
      allowEdit: true,
      destinationType: Camera.DestinationType.FILE_URI
    });

            // Change image source and upload photo to server
    function uponSuccess(imageURI) {

        // Set image source
        var image = document.getElementById('fileuploadimg');
        $$('.gAlbumList').append('<a href="#"><img src="'+imageURI  + '?' + Math.random()+'" /></a>');


        var options = new FileUploadOptions();
        options.fileKey = "file";
        options.fileName = imageURI.substr(imageURI.lastIndexOf('/') + 1);
        options.mimeType = "image/jpeg";

        var params = {};
        params.value1 = "test";
        params.value2 = "param";

        options.params = params;
        options.chunkedMode = false;

        var ft = new FileTransfer();

        ft.upload(imageURI, "https://example.com/dummy.php", function(result){
            $$('.error').append('<p>successfully uploaded ' + result.response+'</p>');
        }, function(error){
            $$('.error').append('<p>error : ' + JSON.stringify(error)+'</p>');
        }, options);

    }

    function uponFail(message) {
        $$('.error').append('<p>Failed because: ' + message+'</p>');
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM