|
[云开发]
model.uploadFile上传失败
[复制链接]
model.uploadFile上传失败,提示:{"msg":"invalid request","status":0,"code":0}
附源码功能:个人中心上传头像文件
//init personal center
function initPersonalCenter(json) {
api.showProgress({
title: '加载中...',
modal: false
});
json = json || {};
if (!json.nickname) {
return;
}
var uid = $api.getStorage('uid');
var pc = api.require('personalCenter');
var headerH = api.pageParam.headerHeight;
var photo = json.photo || 'widget://image/userTitle.png';
var point = json.point || 0;
pc.open({
y: 0,
height: 150,
fixedOn: 'user',
fixed: true,
imgPath: photo,
placeHoldImg: photo,
showLeftBtn: false,
showRightBtn: false,
username: json.nickname,
count: point,
btnArray:[{}],
modButton: {
bgImg: 'widget://image/edit.png',
lightImg: 'widget://image/edit.png'
},
},function(ret,err){
api.confirm({
title:"修改头像",
msg:"您想要从哪里选取图片?",
buttons:["自拍","相册","取消"]
},function(ret,err){
var sourceType = "album";
if (3 == ret.buttonIndex){
return;
}
if (1 == ret.buttonIndex){
sourceType = "camera";
}
api.getPicture({
sourceType: sourceType,
encodingType: 'png',
mediaValue: 'pic'
},function(ret,err){
if (ret){
pc.updateValue({
imgPath: ret.data,
});
var imgUrl = ret.data;
var imgName = imgUrl.substr(imgUrl.lastIndexOf('/')+1);
//alert(imgUrl);alert(imgName);
var model = api.require('model');
var appId = 'A698**********';
var key = '0507A1BD-5E2A-D7E9-****-************';
var now = Date.now();
var appKey = SHA1(appId + "UZ" + key + "UZ" + now) + "." + now;
model.config({
appId : appId,
appKey : appKey
});
model.uploadFile({
report:false,
data:{
file:{
name:imgName,
//url: 'widget://image/car.png'//imgUrl
url : 'widget://' + imgUrl
}
}
},function(ret, err) {
if (ret) {
alert(JSON.stringify(ret));//alert(ret.data);
} else {
}
});
}
});
});
return;
}
)
api.hideProgress();
}
|
|