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

Not able to set limit in body parser #176

Closed
UditKaul opened this issue Jun 9, 2016 · 4 comments
Closed

Not able to set limit in body parser #176

UditKaul opened this issue Jun 9, 2016 · 4 comments
Assignees
Labels

Comments

@UditKaul
Copy link

UditKaul commented Jun 9, 2016

I am trying to increase the limit of request entity allowed in body-parser. I tried this but was no good.
app.use(bodyParser());
app.use(bodyParser({limit: '50mb'}));
app.use(bodyParser.urlencoded({limit: '50mb'}));

The error message says "Error: request entity too large" and the status code is 413.

@UditKaul UditKaul changed the title No able to set limit in body parser Not able to set limit in body parser Jun 9, 2016
@Thanatos-L
Copy link

Thanatos-L commented Jun 16, 2016

I have the same problem and I'm trying to add:

app.use(bodyParser.raw({limit: "50mb"}));

then get error: bodyParser.raw is not a function.

My problem still not be fixed yet.

I use AFNetworking to upload a picture which no more than 1mb.

NSString *urlString = [baseUrlString stringByAppendingString:@"account/avatar"];

    NSDictionary *parameters = @{@"token": self.token};
    NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
    AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];

    NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] requestWithMethod:@"POST" URLString:urlString parameters:parameters error:nil];
    //[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
    //[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    NSURLSessionUploadTask *uploadTask = [manager uploadTaskWithRequest:request fromFile:filePath progress:nil completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
        if (error) {
            NSLog(@"Error: %@", error);
        } else {
            NSLog(@"Success: %@ %@", response, responseObject);
        }
    }];
    [uploadTask resume];

@dougwilson
Copy link
Contributor

Hi @UditKaul, I cannot reproduce your issue, and there is almost no information to go on in your report. Can you please provide all the following?

  1. The version of this module you are using.
  2. The version of Node.js you are using.
  3. A complete app (not just a snippet like you pasted above) that we can copy-and-paste and run. Please include as little other dependencies as possible, to reduce the surface area of the investigation.
  4. Please provide the complete steps to reproduce the issue. This may be a cURL command, for example. Explain what happens when it is not working, and explain what you expect to happen.

@Thanatos-L your issue sounds different from the one above, in particular, your bodyParser variable is either not from this module, or it is a very old version of this module, before raw was added. Please consult the README.md file for the installed body-parser version you are using to determine what functionality is available.

@dougwilson dougwilson self-assigned this Jun 16, 2016
@UditKaul
Copy link
Author

@dougwilson thank you for your concern,but i found a solution to my problem just by doing the following.

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

@dougwilson
Copy link
Contributor

Hi @UditKaul, oh, wow, I'm really sorry, but I actually copy-and-pasted your code incorrectly myself when I tried to test! So the reason why

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

does not work is because you are using it over and over. I was assuming that you were simply showing three different ways, not that you actually had all three of those in your code. You see, you are actually defining the same body parsing multiple times for no reason, and since bodyParser() byt itself will parse both url encoded and json bodies, it it always meet first, and the second two literally do nothing.

Now in your new example, the first app.use(bodyParser({limit: '50mb'})); does all the work while your other two statements are doing absolutely nothing, so you can simply remove them.

@expressjs expressjs deleted a comment from ShreyaMishra22 Jul 15, 2019
@expressjs expressjs deleted a comment from riginoommen Jul 15, 2019
@expressjs expressjs deleted a comment from omt66 Jul 15, 2019
@expressjs expressjs deleted a comment from Dajust Jul 15, 2019
@expressjs expressjs deleted a comment from keithmichelson Jul 15, 2019
@expressjs expressjs deleted a comment from riginoommen Jul 15, 2019
@expressjs expressjs locked as resolved and limited conversation to collaborators Jul 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants