How to do file upload? (please add to readme.md)
See original GitHub issueI 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?
Issue Analytics
- State:
- Created 7 years ago
- Comments:21 (6 by maintainers)
Top Results From Across the Web
How to: Upload Readme files, and why you should - YouTube
In this video we will cover how to upload readme files while taking advantage of HydroShare's built in Readme file functionality.
Read more >Attaching files to markdown files | GitHub Changelog
Just drag and drag, click and select, or paste. Drop to upload a gif. Note: If you add an image to a markdown...
Read more >Adding Images to Github README.md - Fatima Yousif - Medium
Adding Images to the README file as screenshots of the project you have completed, will make it more readable with pictorial representation of...
Read more >Inserting Files into Markdown Pages - MarineGEO
Navigate to the folder where you want to upload the asset (image, pdf, etc). Click the Upload Files button and drag files that...
Read more >How to Add Images on README .md File in a GitHub ...
An image can be represented in the following formats: JPEG; PNG; SVG. Procedure: In order to add an image to the README file...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
If anyone comes across this in the future and needing to upload a buffer stream, this solution worked for me. Following code is for request so just make sure to convert to request-promise properly 😃
http://stackoverflow.com/a/43020398/7798791
I don’t think this is a request-promise issue, but a npm request that request-promise uses.
But from what I can tell you should be using formData, and not form, and you shouldn’t need to set the headers manually. I also think the json=true is not required.
eg.