Ashok Singh
Ashok Singh

Reputation: 33

How to proxy multipart file in fastify 2.15

I have implemented a gateway proxy server for backend server which actually serve all requests using axios .

In case on multipart request it fails and nothing reaches backend server.

proxy server:

using fastify multipart plugin in gateway.

app.register(require("fastify-multipart"), { addToBody: true });

handelling request:

handle : async (request) => {
  
 const formData = new FormData();
    const keys = Object.keys(JSON.parse(request.body))
    const buffer = JSON.parse(request.body)[keys[0]][0]
    formData.append('my_field', keys[0]);
    formData.append('my_buffer', buffer.data.data[0]);

config = {
      qs : queryStringParameters,
      method : 'POST',
      headers : { 
        "Content-Type" : headersNormalized['content-type'],
        "User-Agent" : headersNormalized['user-agent'],
        "client-version": headersNormalized['androidversionname'],
        "Content-Length": headersNormalized['content-length'],
      },
      body: formData,
      raw : true
    }

    const { status, data } = await http(request).LB("/downstream/upload", config)
}

sending .png(which is recieved in body in gateway and then I am sending it in form/multipart data).

in downstream server, it is expecting data in form :

app.register(require("fastify-multipart"));

I am trying above code but it's giving 500 every-time.

Please give some direction of how to proceed on implementing "multipart file upload proxy gateway" using fastify and nodejs.

Upvotes: 1

Views: 339

Answers (0)

Related Questions