question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Attach() should put files on request.files?

See original GitHub issue

Hello, this is more a doubt than a issue.

I’m using the method attach() to simulate a file upload to a express middleware. I was expecting that the request.files would be filled with the information of the attached file, but instead I’m receiving an undefined variable on request.

Am I doing something wrong?

request(app)
      .post('/test')
      .attach('image', __dirname + '/fixtures/fatcat.jpeg')
      .expect('Content-Type', /json/)
      .expect('Content-Length', '15')
      .expect(201)
      .end(function(err, res){
        if (err) throw err;
        done();
      });

middleware

return function handler(req, res, next) {
      console.log(req.files); // returns undefined :(
}

Thanks in advance.

Issue Analytics

  • State:closed
  • Created 11 years ago
  • Comments:15 (1 by maintainers)

github_iconTop GitHub Comments

15reactions
radiumrasheedcommented, Jan 17, 2019

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')
6reactions
ghostcommented, Feb 27, 2017

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Attach() should put files on request.files? · Issue #47 - GitHub
Hello, this is more a doubt than a issue. I'm using the method attach() to simulate a file upload to a express middleware....
Read more >
javascript - how to attach a file to request so that it shows up ...
The way I have found examples are: const file = fs.readFileSync(filePath) const formData = new FormData() formData.append('userId', ...
Read more >
Create a file request - Microsoft Support
Click Select files, browse to the appropriate folder, and select the file being requested. If you need to add additional files, select Add...
Read more >
Request Files - FastAPI
You don't have to use File() in the default value of the parameter. · It uses a "spooled" file: · This means that...
Read more >
Uploading Files — Flask Documentation (2.2.x)
Let's start with a very basic application that uploads a file to a specific upload folder and displays a file to the user....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found