Comments (15)
my solution was to use
.field()
s along with.attach()
(if i remember correctly i even got a warning sometime that.send()
and.attach()
don't work together)i've encountered so many issues with multer and multipart form data, so i'd rather handle
base64
via json
return request
.post('/api/v1/client/1/progress_note')
.field('answers', progressNoteData.answers)
.field('duration', progressNoteData.duration)
.field('templateId', progressNoteData.templateId)
.field('service', progressNoteData.service)
.field('service_time', progressNoteData.service_time)
.attach('attachment', 'test/mock-data/sample-image.png')
from supertest.
my solution was to use.field()
s along with .attach()
(if i remember correctly i even got a warning sometime that .send()
and .attach()
don't work together)
i've encountered so many issues with multer and multipart form data, so i'd rather handle base64
via json
from supertest.
Forgot to put the route declaration:
app.post('/test', uploadHandler, function(req, res){
res.send(201, { name: 'tobi' });
});
from supertest.
You probably didn't use the bodyParser()
middleware in express.
from supertest.
Having same problem... let me know if you sorted it @wlepinski
from supertest.
Wow, this issue very old, @SteveNewhouse I really don't remember what I did so try what @gjohnson said. Good luck.
from supertest.
how to send image files array and with many fields?
from supertest.
@calidion
+1 how to send image files array and with many fields?
from supertest.
You can attach files just as OP described. The problem is that the multipart parser is no longer included in express bodyparser. You need to use a seperate package such as multer to handle multipart/form-data. I just found this out after upgraded my project to express 4.x.
from supertest.
from supertest.
from supertest.
@radiumrasheed .filed
only works if the field is a string
, how can a field of an array or object be handled? I tried creating multiple fields with the same name, but throws error
from supertest.
@radiumrasheed
.filed
only works if the field is astring
, how can a field of an array or object be handled? I tried creating multiple fields with the same name but throws an error
This works by stringify
the field
from supertest.
yes, you need to stringify the array
from supertest.
Adding fields didn't seem to change how attachment was handled for me. I still wasn't able to see it when printing out req.files or req.file.
If someone is still looking for a solution, I used "form.parse" as part of multiparty library on my backend (nodejs) to get the files object from req, in which took me forever to realize that the file was stored on the attachment field on "files" as you can see below.
exports.nodeFunction = function (req, res) {
var form = new multiparty.Form({
uploadDir: 'app/tmp'
});
form.parse(req, function (err, fields, files) { // https://www.npmjs.com/package/multiparty
var file = files.file ? files.file[0] : files.attachment[0];
// when uploaded on front end, files.file has the file, but files.attachment holds the file when using supertest in mocha.
});
Here's my test function as well:
describe('POST', function () { it('Should upload file', async function () { const res = await request(app).post(url) // request = require('supertest') .attach('attachment', path.resolve(__dirname, filename)) // using "path" library .expect(200) }); });
@gjohnson I have the updated body-parser for Express and it still does not work. This issue should be re-opened unless a solution is provided.
from supertest.
Related Issues (20)
- Notice regarding the move from @visionmedia org to @ladjs org
- Cookies go to domains they didn't return from
- disabling the debug REQURL CODE line that comes while testing HOT 1
- HTTP2 sample no working
- [fix] TypeError: Cannot read properties of undefined (reading 'address') HOT 1
- cookiejar Regular Expression Denial of Service via Cookie.parse function HOT 3
- `_body` key instead of `body` in response HOT 1
- Its is a good practice for Next.js?
- [fix] timeout doesn't call end with error
- [fix] Module not found: Error: Can't resolve 'http' in '[...]/node_modules/supertest/lib' HOT 1
- [fix] Do no replace invalid body with an empty JSON object HOT 1
- I didnt find supertest latest version updated with latest superagent 8.0.9 HOT 3
- Why I was getting "Jest has detected the following 1 open handle potentially keeping Jest from exiting: Timeout"
- Error: write EPIPE on large files - Next.js + Jest + Supertest HOT 1
- [fix] Cannot send secure cookie over unencrypted connection
- [fix] Next.js: Ubuntu 22.04.3 LTS
- [fix] don't change the requrest url hash HOT 1
- SuperTest is not compatible with Node v18.19.0 Error: ECONNREFUSED: Connection Refused HOT 3
- [fix] write EPIPE error when attaching a file. (small repro)
- supertest version 6.3.3 => 6.3.4 is a breaking change HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from supertest.