【发布时间】:2014-12-04 22:44:05
【问题描述】:
我正在使用 MEANJS 堆栈,我使用 ng-flow 上传图像并将 imgsrc 保存为 base64 url。
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAARkAAACzCAYAAAC94GgrA....
这是我的猫鼬模式:
var ServiceSchema = new mongoose.Schema({
name : String,
url: String,
description : String,
category : String,
imgsrc: String
});
对于大图像,我遇到了Request Entity Too Large服务器错误。
我可以在上传之前调整图片大小,但这仍然只允许我的图片大小为 200 x 200
$scope.resizeimageforupload = function(img){
var canvas = document.getElementById('canvas');
var MAX_WIDTH = 200; //400; too big still
var MAX_HEIGHT = 200; //300 too big still
var width = img.width;
var height = img.height;
if (width > height) {
if (width > MAX_WIDTH) {
height *= MAX_WIDTH / width;
width = MAX_WIDTH;
}
} else {
if (height > MAX_HEIGHT) {
width *= MAX_HEIGHT / height;
height = MAX_HEIGHT;
}
}
canvas.width = width;
canvas.height = height;
var ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0, width, height);
var dataURL = canvas.toDataURL("image/png");
dataURL.replace(/^data:image\/(png|jpg);base64,/, "");
return dataURL;
};
关于变通或替代解决方案的任何想法?
请求实体太大:413
错误:请求实体太大
在 makeError (Angular\expresstest\node_modules\body-parser\node_modules\raw-body\index.js:184:15)
在 module.exports (Angular\expresstest\node_modules\body-parser\node_modules\raw-body\index.js:40:15)
读取时(Angular\expresstest\node_modules\body-parser\lib\read.js:62:3)
在 jsonParser (Angular\expresstest\node_modules\body-parser\lib\types\json.js:87:5)
在 Layer.handle [as handle_request] (Angular\expresstest\node_modules\express\lib\router\layer.js:76:5)
在 trim_prefix (Angular\expresstest\node_modules\express\lib\router\index.js:270:13)
在 Angular\expresstest\node_modules\express\lib\router\index.js:237:9
在 Function.proto.process_params (Angular\expresstest\node_modules\express\lib\router\index.js:312:12)
在 Angular\expresstest\node_modules\express\lib\router\index.js:228:12
在 Function.match_layer (Angular\expresstest\node_modules\express\lib\router\index.js:295:3)
【问题讨论】:
标签: javascript angularjs mongodb mongoose mean-stack