-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Manually set content-type when using .attach #1152
Comments
No, there's no way. Setting it will break things. In the browser version the boundary is set automatically by |
@pornel So theres literally no way i can use the same boundary in my payload as my header? |
You can't use |
@pornel Okey, so theres still a chance! Can you send images with .send()? :) (if so how?) |
The hard way. Generate boundary, content-type header, and append image's binary data. You'll need to get Uint8Array from image Blob (using FileReader). I'd rather do it the other way — why do you use your raw, custom payload? Can you send it as files or form fields instead? |
@pornel I'm trying to upload a picture to a website (not mine), i've checked the network requests and i need to provide the image and a payload. The payload consists of information regarding the image, like this
And the content-type (WebKitFormBoundaryKWf3FhTClwfaDpre) must match. I'm not sure how to do it |
What do you use .send() for? Usually you only need request
.post('http://website.com/upload')
.attach("image", image, "2684337397.jpg")
.then(…) and nothing else. The boundary is supposed to be random, so needing it to match anything is very unusual. |
@pornel The payload also consists of eventvalidation and some viewstate string, so it seems to be required (using only attach doesn't work). Is the server expecting .attach("image", image, "2684337397.jpg") to be something specific? If so, how can i figure that out? |
You can add other data using the only limitation of .field and .attach is that it sends the form the same way as browser would send |
@pornel I just got it working, thank you a lot! I've got a new, simpler problem. i'm sending some text via .send(), the site uses charset ISO-8859-1. I tried setting the charset with
This has worked previously when reading the response. But when i'm sending, the text coming up on the site is encoded weirdly. å showing up as Ã¥ etc. Is there a specific method of setting the charset of .send()? Should i make a new issue for this? Thanks a lot |
Please make a new issue for the other problem |
Hey!
I'm sending a request like this
However, the content-type gets overridden by superagents own value. Resulting in a res.req._headers like this
content-type': 'multipart/form-data; boundary=--------------------------442535245526379898253153
Is there any way i can force set the content-type manually?
Or perhaps figure out superagents content-type pre-post so i can use the same boundary in my .send(payload)
The text was updated successfully, but these errors were encountered: