简体   繁体   English

Phonegap FileTransfer上传返回空值

[英]Phonegap FileTransfer Upload Returning Null

I have been trying to figure this out for a few days now. 我已经尝试了好几天了。 The tutorials and documents all say the same thing. 教程和文档都说相同的话。

I want to upload a photo the user takes with the camera. 我想上传用户用相机拍摄的照片。 However, it keeps hitting the error function and saying code, source, and target are null. 但是,它一直点击错误函数,并说代码,源和目标为空。 My server never gets hit and there seems to be nothing about it. 我的服务器永远不会受到攻击,而且似乎什么也没有。 Here is my code. 这是我的代码。

$(function() {

$('#camera').click(function() {
    navigator.camera.getPicture(upload, function() {
        alert('error');
    },
    {
        quality: 50, 
        destinationType: navigator.camera.DestinationType.FILE_URI,
        sourceType: navigator.camera.PictureSourceType.CAMERA
    }); 
});

var upload = function(image) {

    console.log(image);

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

    console.log(image.substr(image.lastIndexOf('/')+1));

    options.chunkedMode = true;

    var ft = new FileTransfer();
    ft.upload(image, encodeURI("http://mysite/upload.php"), win, fail, options);

};

function win(r) {
    console.log("Code = " + r.responseCode);
    console.log("Response = " + r.response);
    console.log("Sent = " + r.bytesSent);
}

function fail(error) {
    alert("An error has occurred: Code = " + error.code);
    console.log("upload error source " + error.source);
    console.log("upload error target " + error.target);
}

});

config.xml config.xml中

<access origin="*" />

Are you using the Telerik platform by any chance? 您是否正在使用Telerik平台? If so, that would be the reason. 如果是这样,那就是原因。 This platform is currently limited in some aspects and does not support the File and File Transfer API. 该平台当前在某些方面受到限制,并且不支持文件和文件传输API。 Here's a list of limitations of the simulator. 这是模拟器的局限性列表。 That is why FileTransfer would return null instead of an error code. 这就是FileTransfer将返回null而不是错误代码的原因。

http://docs.telerik.com/platform/appbuilder/testing-your-app/running-apps-in-simulator/limitations-device-simulator http://docs.telerik.com/platform/appbuilder/testing-your-app/running-apps-in-simulator/limitations-device-simulator

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

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