How to upload files using nodejs and HAPI?

前端 未结 3 1729
面向向阳花
面向向阳花 2020-12-28 17:44

Can anyone tell me How to upload files Using nodejs and HAPI?

I am getting binary data inside the handler.

Here is my html code:

function sen         


        
3条回答
  •  囚心锁ツ
    2020-12-28 18:19

    For new readers, hapi already using multiparty uses pez to handle multipart post requests. From hapi documentation;

    If the payload is 'multipart/form-data' and parse is true, fields values are presented as text while files are provided as streams. File streams from a 'multipart/form-data' upload will also have a property hapi containing filename and headers properties.

    Example;

    server.route({
       method: 'POST',
       path: '/create',
       config: {
          payload:{
                maxBytes: 209715200,
                output:'stream',
                parse: true
          }, 
          handler: function (request, reply) {
              request.payload["htmlInputName"].pipe(fs.createWriteStream("test"));
          }
    });
    

提交回复
热议问题