Skip to content
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

can not post a binary file with content type as 'image/jpeg' using attach() #174

Closed
vaibhavpuri opened this issue Sep 13, 2017 · 1 comment

Comments

@vaibhavpuri
Copy link

I want to pass the file as binary to one of my functions which i want to write the test around using chai http, below is the code:

              chai.request('http://localhost:8085')
                .post('/myAPI/' + req.params.id + '/logo')
                .attach('image', fs.readFileSync(__dirname + '/resources/IMG_86425.jpg'), 'IMG_86425.jpg')
                .set('Content-Type','image/jpeg')
                .end((err, res) => {
                    should.equal(err, null);
                    res.status.should.equal(200);
                    res.should.be.json;
                    done();
                });

Problem is that attach() inherently seem to update the content type to multipart form data in spite of me trying to over ride it with image/jpeg.
Is there something we can do to override this behaviour of attach() or is there any other way i can post binary data to my function.

Thanks

@vaibhavpuri vaibhavpuri changed the title can not post a binary file with content type as 'image/jpeg' using attach attach() can not post a binary file with content type as 'image/jpeg' using attach() Sep 13, 2017
@vaibhavpuri
Copy link
Author

attach is meant to work for multi part form data, for sending file as binary i used:

.send(fs.readFileSync(__dirname + '/resources/IMG_86425.jpg'))
.set('Content-Type','image/jpeg')
Solves the problem...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant