MEANJS:将base64映像发送到服务器的最佳方法

情况

我使用MEAN.JS框架( MongoDB , ExpressJS , AngularJS和NodeJS )。

在前端使用AngularJS ; 我有一个字段中的base64编码图像JSON

我想要的是?

  • 我想发送这个JSON到服务器( NodeJS )。

我正在使用RESTful

控制器

var article = new Articles ($scope.article); article.$save(function(response) { //If all is OK }, function(errorResponse) { //Error }); 

$scope.article有一个名为“ image($ scope.article.image)的图像的base64string。

服务:

 (function() { 'use strict'; angular .module('articles') .factory('articles', ['$resource', function($resource) { return $resource('articles/:articleId', { articleId: '@_id' }, { update: { method: 'PUT' } }); } ]);})(); 

问题

如果JSON没有任何Base64图像在一个领域工作正常…

但…

如果我们添加图像的Base64string在一个字段的服务器响应与此错误

  Error: request entity too large at makeError (/Users/aralroca/Documents/Aral/Projecte/node_modules/body-parser/node_modules/raw-body/index.js:184:15) at module.exports (/Users/aralroca/Documents/Aral/Projecte/node_modules/body-parser/node_modules/raw-body/index.js:40:15) at read (/Users/aralroca/Documents/Aral/Projecte/node_modules/body-parser/lib/read.js:62:3) at jsonParser (/Users/aralroca/Documents/Aral/Projecte/node_modules/body-parser/lib/types/json.js:96:5) at Layer.handle [as handle_request] (/Users/aralroca/Documents/Aral/Projecte/node_modules/express/lib/router/layer.js:82:5) at trim_prefix (/Users/aralroca/Documents/Aral/Projecte/node_modules/express/lib/router/index.js:269:13) at /Users/aralroca/Documents/Aral/Projecte/node_modules/express/lib/router/index.js:236:9 at Function.proto.process_params (/Users/aralroca/Documents/Aral/Projecte/node_modules/express/lib/router/index.js:311:12) at /Users/aralroca/Documents/Aral/Projecte/node_modules/express/lib/router/index.js:227:12 at Function.match_layer (/Users/aralroca/Documents/Aral/Projecte/node_modules/express/lib/router/index.js:294:3) 

说请求实体太大 …图像大小是84Kb !!!!!

(我尝试使用$ http资源 ,发生相同…)

  • 我该如何解决这个服务器错误?
  • 从Angular向Node发送Base64编码图像的最佳方式是什么?
  • 有什么build议么?

相关答案:

  • 错误:请求实体太大
  • 意见:413(要求实体太大)

我试图做到这一点,但不工作,不明白:

  app.use(bodyParser.urlencoded({limit: '50mb'})); app.use(bodyParser.json({limit: '50mb'})); 

bodyParser被弃用,Base64图像的大小是84kb!

谢谢!!

尝试使用:

 var express = require('express'); var app = express(); var busboy = require('connect-busboy'); app.post("/url_path", busboy({ limits: { fileSize: 10 * 1024 * 1024 } }), function(req, res, next) { // check that the request's body was as expected if (!req.busboy) return next('route'); // or next(new Error('...')); // ... }); 

// …

欲了解更多信息结帐这个私人NPM 。