使用cordova File-Transfer插件我嘗試上傳圖片。 但上傳失敗。 我的代碼如下所示。cordova上的文件上傳失敗
function capturePhoto() {
navigator.camera.getPicture(
uploadPhoto,
onFail,
{quality: 50, destinationType: Camera.DestinationType.FILE_URI}
);
}
function uploadPhoto(imageURI) {
console.log(imageURI);
var largeImage = document.getElementById('largeImage');
largeImage.style.display = 'block';
largeImage.src = imageURI;
var options = new FileUploadOptions();
options.fileKey = "file";
var userid = '123456';
var imagefilename = userid + Number(new Date()) + ".jpg";
options.fileName = imagefilename;
options.mimeType = "image/jpg";
var params = new Object();
params.imageURI = imageURI;
params.userid = '1';//sessionStorage.loginuserid;
options.params = params;
options.chunkedMode = false;
var ft = new FileTransfer();
var url = "http://localhost:8080/video/upload.php";
//console.log('sd');
ft.upload(imageURI, url, win, fail, options, true);
}
function win(r) {
console.log("Image uploaded successfully!!");
}
function fail(error) {
console.log(error);
console.log("There was an error uploading image");
}
function onFail(message) {
console.log('Failed because: ' + message);
}
在此先感謝。
什麼是在後端,?通過https://gonzalo123.com/2013/10/28/taking-photos-with-a-phonegapcordova-application-and-uploading-them-to-the-server/,它會幫助你 – Naitik
後端是PHP。它在我的本地服務器上運行。 – Rahul