上传图片

//上传图片

functionuploadImage(filePath) {

//filePath = 'images/logo.png';

varwd=plus.nativeUI.showWaiting();

varserverIP=plus.storage.getItem('serverIP');

varurl=serverIP+'/WebComment/handle/uploadImage?';

console.log('url: '+url);

console.log('filePath: '+filePath);

vartask=plus.uploader.createUpload(url, {

method:"POST",

data:{

"string_key":"chatImage"

}

},

function(t,status) {

// 上传完成

if(status==200) {

wd.close();

varobj=JSON.parse(t.responseText);

varfileName=obj.fileName;

sendHandleImagePaths(fileName);

//alert("Upload success: " + fileName);

//alert("Upload success: " + t.url);

}else{

wd.close();

alert("Upload failed: "+status);

}

}

);

vardstPath="_doc/chartCompressedImage.jpg";

plus.zip.compressImage({

src:filePath,

dst:dstPath,

quality:20,

overwrite:true

},

function() {

//alert("Compress success!");

task.addFile(dstPath, {

key:"chatImage"

});

task.addData("string_key","string_value");

//task.addEventListener( "statechanged", onStateChanged, false );

task.start();

},

function(error) {

alert("Compress error!");

task.addFile(filePath, {

key:"chatImage"

});

task.addData("string_key","string_value");

//task.addEventListener( "statechanged", onStateChanged, false );

task.start();

});

}

你可能感兴趣的:(上传图片)