我正在使用MEANJS技术栈,使用ng-flow上传图像,并将imgsrc保存为base64 url。
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAARkAAACzCAYAAAC94GgrA....
这是我的mongoose模式:
var ServiceSchema = new mongoose.Schema({
name : String,
url: String,
description : String,
category : String,
imgsrc: String
});
我上传大图片时遇到了请求实体过大的服务器错误。
虽然我可以在上传之前调整图片大小,但这仍然只允许我上传尺寸为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
错误:请求实体过大 at makeError (Angular\expresstest\node_modules\body-parser\node_modules\raw-body\index.js:184:15) at module.exports (Angular\expresstest\node_modules\body-parser\node_modules\raw-body\index.js:40:15) at read (Angular\expresstest\node_modules\body-parser\lib\read.js:62:3) at jsonParser (Angular\expresstest\node_modules\body-parser\lib\types\json.js:87:5) at Layer.handle [as handle_request] (Angular\expresstest\node_modules\express\lib\router\layer.js:76:5) at trim_prefix (Angular\expresstest\node_modules\express\lib\router\index.js:270:13) at Angular\expresstest\node_modules\express\lib\router\index.js:237:9 at Function.proto.process_params (Angular\expresstest\node_modules\express\lib\router\index.js:312:12) at Angular\expresstest\node_modules\express\lib\router\index.js:228:12 at Function.match_layer (Angular\expresstest\node_modules\express\lib\router\index.js:295:3)