Ajax error when using image upload module multiparty in node.js

Asked 2 years ago, Updated 2 years ago, 54 views

Cho Daehyuk's blog http://bcho.tistory.com/1078

Here, we use the multiparty module to study uploading images.

It works fine if you follow the example.

Ajax method

$.ajax({
    type: "post",
    url: "/users/upload",
    data: $("#uploadForm").serialize(),
    // // dataType: "json",
    // // contentType: "application/x-www-form-urlencoded; charset=utf-8",
    success: function (data) {
      console.log('success: ', data);
    },
    error: function (jqXHR, textStatus, errorThrown) {
      console.log('jqXHR: ', jqXHR.status);
      console.log('message: ', jqXHR.responseText);
      console.log('error: ', errorThrown);
    }
});

Hani with

Error: unsupported content-type
    at Form.parse (/Users/hanman/Documents/workspace/prj_test/node_modules/multiparty/index.js:160:21)
    at /Users/hanman/Documents/workspace/prj_test/routes/users.js:346:12
    at Layer.handle [as handle_request] (/Users/hanman/Documents/workspace/prj_test/node_modules/express/lib/router/layer.js:95:5)
    at next (/Users/hanman/Documents/workspace/prj_test/node_modules/express/lib/router/route.js:131:13)
    at Route.dispatch (/Users/hanman/Documents/workspace/prj_test/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/Users/hanman/Documents/workspace/prj_test/node_modules/express/lib/router/layer.js:95:5)
    at /Users/hanman/Documents/workspace/prj_test/node_modules/express/lib/router/index.js:277:22
    at Function.process_params (/Users/hanman/Documents/workspace/prj_test/node_modules/express/lib/router/index.js:330:12)
    at next (/Users/hanman/Documents/workspace/prj_test/node_modules/express/lib/router/index.js:271:10)
    at Function.handle (/Users/hanman/Documents/workspace/prj_test/node_modules/express/lib/router/index.js:176:3)
    at router (/Users/hanman/Documents/workspace/prj_test/node_modules/express/lib/router/index.js:46:12)
    at Layer.handle [as handle_request] (/Users/hanman/Documents/workspace/prj_test/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/Users/hanman/Documents/workspace/prj_test/node_modules/express/lib/router/index.js:312:13)
    at /Users/hanman/Documents/workspace/prj_test/node_modules/express/lib/router/index.js:280:7
    at Function.process_params (/Users/hanman/Documents/workspace/prj_test/node_modules/express/lib/router/index.js:330:12)
    at next (/Users/hanman/Documents/workspace/prj_test/node_modules/express/lib/router/index.js:271:10)

An error occurs.

What is the difference between direct transfer of form and transmission of Ajax... <

Is there anyone who can help me? ㅜ<

ajax node.js multiparty image

2022-09-21 15:34

1 Answers

Did you set enctype="multipart/form-data" in the form?

I think it's an unsupported content-type error because it's not set.


2022-09-21 15:34

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.