我得到它的工作,這裏是我用
uploadFile('test.zip', 'Test', 'multipart/x-zip');
function uploadFile(fileName, dirName, fileMime) {
var win = function(r) {
console.log("Code = " + r.responseCode);
console.log("Response = " + r.response);
console.log("Sent = " + r.bytesSent);
alert(r.response);
};
var fail = function(error) {
alert("An error has occurred: Code = " = error.code);
};
var fileURI;
var gotFileSystem = function(fileSystem) {
fileSystem.root.getDirectory(dirName, {
create : false
}, function(dataDir) {
fileURI = dataDir.fullPath;
fileURI = fileURI + '/' + fileName;
alert(fileURI);
var options = new FileUploadOptions();
options.fileKey = "file";
options.fileName = fileURI.substr(fileURI.lastIndexOf('/') + 1);
options.mimeType = fileMime;
var params = new Object();
params.value1 = "test";
params.value2 = "param";
options.params = params;
var ft = new FileTransfer();
ft.upload(fileURI,
// Enter the server url
"http://example.com/upload.php", win,
fail, options);
}, dirFail);
};
// file system fail
var fsFail = function(error) {
alert("failed with error code: " + error.code);
};
// get file system to copy or move image file to
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFileSystem,
fsFail);
var dirFail = function(error) {
alert("Directory error code: " + error.code);
};
}
難道bcoz錯誤的URI的代碼?有沒有辦法獲得SD卡的正確URI?試着用'file:///test/test.zip'和'content://media/external/test/test.zip' –
你指出的FileAPI表示出現錯誤。該錯誤將在FileTransferError對象的錯誤回調中報告。那個對象說什麼? –
獲取錯誤「錯誤回調錯誤:FileTransfer3 = ReferenceError:分配中無效的左側」。但是,如果將FILEURI作爲「content:// media/external/images/media/963」給出,我可以成功上傳圖像。我認爲我的zip文件URL有問題? –