-
-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upload file with file;filename (multiple parameters) #197
Comments
Finally I did. I add here some minimum example (I was not able to do it using FormDataAddon): import * as fs from "fs"
import * as path from "path"
import FormData from 'form-data'; // this is the same library than wretch use, so i guess it should not be any problem
const duckImagePath = path.resolve(__dirname, "duck.jpg") // just place a duck.jpg in your working folder
const duckImage = fs.readFileSync(duckImagePath)
export function postFormData() {
const formData = new FormData();
formData.append('file', duckImage, {filename: 'little-duck.jpg'});
return wretch('https://anyurlyouwant.free.beeceptor.com')
.headers(formData.getHeaders())
.url('/files')
.body(formData.getBuffer())
.post()
.res(console.log)
.catch(console.error)
}
postFormData() Result: ` �����JFIF������C�������������������������� � Maybe, a little more documentation or examples about this topic would be great |
Hey @jaimesemp,
As you noticed, the
Glad you nailed it in the end!
I will add a little something in the addon documentation 👍. |
Hi, thanks a lot for this library.
I have been using it deeply, but I have some struggles with multipart/forms.
I want to change this part of the result request:
Content-Disposition: form-data; name="file"
to:
Content-Disposition: form-data; name="file"; filename="datasheet5.pdf"
I have tried the
FormDataAddon
, and the.body(formData)
methods, but I have been unable to add this second parameter, in fact, I do not have any clue at all of how to achieve it.I am using wretch in my custom library (I want to use it on backend & frontend)
Could any give me some hints?
Thanks in advance
The text was updated successfully, but these errors were encountered: