微信上传头像大小限制为1M

weixin_guange
yuanke 9 years ago
parent 2bb2a64dde
commit 18fbf305c1

@ -27,11 +27,18 @@ module Mobile
dirPath = "public/images/avatars/User"
fileDir = dirPath + "/"+current_user.id.to_s
begin
File.open(fileDir,'wb'){ |f| f.write(Base64.decode64(params[:imgdata].split(",")[1])) }
present :status, 0
rescue
imgdata = Base64.decode64(params[:imgdata].split(",")[1])
if imgdata.length > 1024*1024
present :message,"上传图片不能超过1M"
present :status, -1
else
begin
File.open(fileDir,'wb'){ |f| f.write(imgdata) }
present :status, 0
rescue
present :message,"上传失败"
present :status, -1
end
end
end

@ -31,6 +31,6 @@ button:
name: "联系我们"
key: "FEEDBACK"
-
type: "click"
name: "解除绑定"
key: "UNBIND"
type: "view"
name: "个人资料"
url: "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09454f171153c2d&redirect_uri=https://test.forge.trustie.net/wechat/user_activities&response_type=code&scope=snsapi_base&state=edit_userinfo#wechat_redirect"

@ -14,7 +14,7 @@ app.directive('loadHead',['$http','config','auth','$location','alertService',fun
var reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = function (e) {
alert(this.result);//base64
// alert(this.result);//base64
$http.post(config.apiUrl + "users/upload_head",
{token: auth.token(),imgdata:this.result}
@ -25,7 +25,7 @@ app.directive('loadHead',['$http','config','auth','$location','alertService',fun
});
}
else{
scope.$parent.alertService_1.showMessage('提示',"上传失败");
scope.$parent.alertService_1.showMessage('提示',response.data.message);
}
});
}

Loading…
Cancel
Save