文件上传到服务端
牛刀小试
选择文件并上传
示例代码
var uploadUrl = encodeURI("http://dev.bingocc.cc:8060/bingotouch-demo/upload");
$("#btnGetFile").tap(function() {
// Retrieve image file location from specified source
navigator.camera.getPicture(uploadPhoto,
function(message) { alert('get picture failed'); },
{ quality: 50,
destinationType: navigator.camera.DestinationType.FILE_URI,
sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY }
);
});
function uploadPhoto(imageURI) {
app.progress.start("温馨提示","文件上传中...");
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;
var ft = new FileTransfer();
ft.upload(imageURI, uploadUrl, win, fail, options);
}
function win(r) {
var html = "ResponseCode = " + r.responseCode + "
" +
"Response = " + r.response + "
" +
"Sent = " + r.bytesSent + "bytes";
$("#fu_result").html(html);
app.progress.stop();
}
function fail(error) {
var html = "An error has occurred: Code = " + error.code + "
" +
"upload error source: " + error.source + "
" +
"upload error target: " + error.target;
$("#fu_result").html(html);
app.progress.stop();
}