Pure Node.js file upload (multipart POST) without using a framework

后端 未结 3 854
半阙折子戏
半阙折子戏 2021-01-18 05:32

The third-party libraries \"node-formidable\" and \"express\" come with the ability to handle multipart POST requests (e.g. with a file upload form), but I don\'t want to us

3条回答
  •  盖世英雄少女心
    2021-01-18 06:10

    I think you need to parse form by yourself if you don't want to use any modules very much. When uploading a file, the form will be in multipart/form-data format, which means your request content will be divided by a string that is generated randomly by your browser. You need to read this string at the beginning of the form, try to load data and find this string, then parse them one by one.

    For more information about multipart/form-data you can refer http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.2

    I think the best solution is to use formidable. It handles vary scenarios and works prefect I think.

提交回复
热议问题