How to do file upload? (please add to readme.md)
I successfully called my hapi.js server route with Postman uploading a file and it looks like this:
Then I tried writing a test to upload a file using request-promise but the “file” arrives like this (incorrect and unusable):
My code looks like this:
const options = { method: 'POST', json: true, uri: testData.url + `uploadprofilephoto`,
headers: { 'token': testData.token, 'Content-Type': 'multipart/form-data; charset=UTF-8'},
form: {
image: fs.createReadStream('/home/rje/photo.jpg')
}
};
const json: IResponse<string> = await request(options);
I tried changing form
to body
so it matched all my other POST calls but then I got a server route crash:
[StatusCodeError: 400 - {"statusCode":400,"error":"Bad Request","message":"Invalid content-type header: multipart missing boundary"}]
What else can I try please?
Is there a better way to turn the file on disk into a Uint8Array to send, rather than readstream?