C
C
Coder3212018-06-19 16:50:03
Node.js
Coder321, 2018-06-19 16:50:03

How to send a file?

I receive pictures in base64 format on the service, I need to send them to another service via multipart/form-data, if I save the file to myself and send it in this way:

function sendFile(){
    const opt = {
        method: 'POST',
        uri: 'path to service',
        formData: { file: createReadStream('path to file') }
    }
    return  requestPromise(opt);
}

then everything works clearly, but somehow I don’t want to do extra operations of saving / deleting the file, is it possible to somehow get around this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladlen Hellsite, 2018-06-19
@Coder321

function sendFile() {
  const opt = {
    method: 'POST',
    uri: 'path to service',
    formData: {
      file: {
        value: Buffer.from(image, 'base64'),
        options: {
          mimeType: 'image/jpeg',
          filename: 'image.jpeg'
        }
      }
    }
  };
  return requestPromise(opt);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question