0

Request entity too large in node which use body parser is a common question and I have see a lot solutions.

The question is, when I am trying to add :

app.use(bodyParser.raw({limit: "50mb"}));// !!!!TypeError: bodyParser.raw is not a function

These code is ok but still I can not upload picture by iOS Afnetworking:

app.use(bodyParser.json({limit: "50mb"}));
app.use(bodyParser.urlencoded({limit: "50mb", extended: true, parameterLimit:50000}));

My bodyParser verision is update to 1.15.1. I use Objective C ,Afnetworking to upload:

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

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


    NSURL *url = [NSURL URLWithString:@"account/avatar" relativeToURL:self.baseUrl];

    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];
Yan Li
  • 1,319
  • 2
  • 12
  • 24
  • So what's not working? What's the question? You said the second piece of code works. – Jeremy Thille Jun 15 '16 at 10:08
  • The first, bodyparser.raw is not work, although second piece could run correctly, iOS still can not upload picture – Yan Li Jun 15 '16 at 10:11
  • take a look @ http://stackoverflow.com/questions/18710225/node-js-get-raw-request-body-using-express – Tareq Jun 15 '16 at 10:12
  • I tried to look the solution to look raw body before but when I console.log(req.rawbody) nothing outputed. – Yan Li Jun 15 '16 at 10:18

0 Answers0