|
楼主 |
发表于 2016-3-28 14:37:12
|
显示全部楼层
本帖最后由 lgz123 于 2016-3-28 14:42 编辑
//需要添加的cordova
var UUID = require("$UI/system/lib/base/uuid");
require("$UI/system/lib/cordova/cordova");
require("cordova!org.apache.cordova.camera");
require("cordova!org.apache.cordova.media-capture");
require("cordova!org.apache.cordova.inappbrowser");
// 拍照按钮事件
Model.prototype.cameraBtnClick = function(event) {
var data = this.comp("UploadData");
function onSuccess(imageData) {
var smallImage = document.getElementById('image2');
alert(321);
smallImage.src = "data:image/jpeg;base64," + imageData;
var name = UUID.createUUID();
alert(123);
data.newData({
index : 0,
"defaultValues" : [{
"uploadName" : name
}]
});
data.saveData();
alert(data.count());
justep.Baas.sendRequest({
"url" : "/cyss/cyss",
"action" : "upload",
"async" : false,
"params" : {
"picPath" : imageData,
"name" : name
},
"success" : function(data) {
justep.Util.hint("图片上传成功");
}
});
}
function onFail(message) {
alert(message);
}
navigator.camera.getPicture(onSuccess, onFail, {
quality : 75,
destinationType : navigator.camera.DestinationType.DATA_URL,
sourceType : navigator.camera.PictureSourceType.CAMERA, // 0、2为从相册文件中选择,1为拍照
encodingType : navigator.camera.EncodingType.JPEG
});
};
baas后台
public static JSONObject getUploadCount(JSONObject params, ActionContext context) throws SQLException, NamingException, IOException {
String picPath = params.getString("picPath");
String name = params.getString("name");
System.out.println("传到后台picPath的值:"+ picPath);
System.out.println("传到后台name的值:" + name);
//OutputStream ous = null;
BASE64Decoder decoder = new BASE64Decoder();
try {
//File file = new File("E:/WeX5/WeX5_V3.3/model/UI2/cyss/"+picPath);//写入位置
//ous = new FileOutputStream(file);
//ous.close();
byte[] decodedBytes = decoder.decodeBuffer(picPath);
String imgFile = "E:/WeX5/WeX5_V3.3/model/UI2/cyss/uploadImg/"+name+".jpg";
FileOutputStream out = new FileOutputStream(imgFile);
out.write(decodedBytes);
out.close();
System.out.println("上传成功!");
} catch (Exception e) {
System.out.println("上传失败!");
e.printStackTrace();
}
return null;
}
|
|