Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to upload base64 encoded file [Error: request entity too large] #536

Closed
tanmays opened this issue Feb 20, 2016 · 4 comments
Closed
Labels
type:feature New feature or improvement of existing feature

Comments

@tanmays
Copy link

tanmays commented Feb 20, 2016

Hello,

I'm using the latest parse-server release v2.1.2 and S3Adapter for saving files. I'm trying to upload a base64 encoded image but I am facing the following error:

Uncaught internal server error. { [Error: request entity too large]
  expected: 273231,
  length: 273231,
  limit: 102400,
  message: 'request entity too large',
  status: 413,
  statusCode: 413,
  type: 'entity.too.large' } Error: request entity too large
    at readStream (/Users/tanmay/parse-server/parse-server-example/node_modules/parse-server/node_modules/body-parser/node_modules/raw-body/index.js:196:17)
    at getRawBody (/Users/tanmay/parse-server/parse-server-example/node_modules/parse-server/node_modules/body-parser/node_modules/raw-body/index.js:106:12)
    at read (/Users/tanmay/parse-server/parse-server-example/node_modules/parse-server/node_modules/body-parser/lib/read.js:76:3)
    at jsonParser (/Users/tanmay/parse-server/parse-server-example/node_modules/parse-server/node_modules/body-parser/lib/types/json.js:121:5)
    at Layer.handle [as handle_request] (/Users/tanmay/parse-server/parse-server-example/node_modules/parse-server/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/Users/tanmay/parse-server/parse-server-example/node_modules/parse-server/node_modules/express/lib/router/index.js:312:13)
    at /Users/tanmay/parse-server/parse-server-example/node_modules/parse-server/node_modules/express/lib/router/index.js:280:7
    at Function.process_params (/Users/tanmay/parse-server/parse-server-example/node_modules/parse-server/node_modules/express/lib/router/index.js:330:12)
    at next (/Users/tanmay/parse-server/parse-server-example/node_modules/parse-server/node_modules/express/lib/router/index.js:271:10)
    at /Users/tanmay/parse-server/parse-server-example/node_modules/parse-server/node_modules/express/lib/router/index.js:618:15

My cloud code is:

Parse.Cloud.define("UploadImageAndGetURL", function(request, response) {

  var fileName = request.params.fileName;
  var base64 = request.params.base64EncodedImageString;

  var file = new Parse.File(fileName, { base64: base64 });

  file.save(null, {useMasterKey:true}).then(function(fileObject) {
      // The file has been saved to Parse.
      var photoURL = fileObject.url();
      console.log("Photo saved successfully with URL:" + photoURL);
      response.success(photoURL);
    }, function(error) {
      // The file either could not be read, or could not be saved to Parse.
      console.log("The file either could not be read, or could not be saved to Parse:" + JSON.stringify(error));
      response.error(error);
  });

});

There is a previously reported issue: #53 when I change the following:

in file parse-server/lib/index.js:line:147

from
api.use(bodyParser.json({ 'type': '*/*' }));
to
api.use(bodyParser.json({ 'type': '*/*',limit: '20mb' }));

file uploading works again.

@gfosco
Copy link
Contributor

gfosco commented Feb 20, 2016

@nlutsenko I would expect the FilesController to have caught this first: https://github.com/ParsePlatform/parse-server/blob/master/src/index.js#L143

But it sounds like adding the 20mb limit to the body everywhere makes sense.

@tanmays
Copy link
Author

tanmays commented Feb 20, 2016

I think we should be able to optionally specify the limit during initialization. There could be scenarios where a certain app would need to set this to a higher/lower value.

@nlutsenko
Copy link
Contributor

Agreed, we should probably allow configuring this, we have a middle on top of file specifically and this configuration would directly set it.

@flovilmart
Copy link
Contributor

@nlutsenko I'll be providing a fix for that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:feature New feature or improvement of existing feature
Projects
None yet
Development

No branches or pull requests

5 participants