Phonegap cordova android 4.4 FileTransfer上传SSL不工作



android的cordova文件传输上传有问题…

我想上传任何类型的文件…意思是图像,视频,声音…

问题是,我不知道如何获得文件的类型/结束(例如。jpg),因为options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);我只得到位置,而不是给定类型/结尾的文件名。当然,我可以只添加+"。jpg",但这并不能帮助所有其他文件,除了图像。这就是我从图片库中选择文件的时候。当我从sd卡中选择一个文件时,什么也没有发生->一定是目标uri

有问题

这是我的代码:

navigator.camera.getPicture(uploadPhotoorfile, function(message) {
}, { quality: 50,
        destinationType: navigator.camera.DestinationType.FILE_URI,
        sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY,
        mediaType: navigator.camera.MediaType.ALLMEDIA  
    });

function uploadPhotoorfile(imageURI) {

var options = new FileUploadOptions();
options.headers = {
    Connection: "close"
};
var options = new FileUploadOptions();
options.chunkedMode = false;
options.fileKey="file";
options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
var params = new Object();
options.params = params;

var ft = new FileTransfer();
ft.upload(imageURI, encodeURI("https://domain....com/doupload.php"), win, fail, options, true); 
}

function win(r) {
console.log("Code = " + r.responseCode);
console.log("Response = " + r.response);
console.log("Sent = " + r.bytesSent);
alert("Success");
}
function fail(error) {
alert("Failed" + error.code);
}

在您的PHP代码中,确保您返回MIME类型作为标题

<?php
  // open the file in a binary mode
  $name = './images/xyz.png';
  $fp = fopen($name, 'rb');
  // send the right headers
  header("Content-Type: image/png");
  header("Content-Length: " . filesize($name));
  // dump the picture and stop the script
  fpassthru($fp);
  exit;
 ?>

如果客户端需要有一个。jpeg扩展名,让你的URL类似于'https://domain....com/myfile.jpg,然后在服务器上执行URL重写,映射URL调用你的PHP页面

最新更新