Sending files over ajax (super agent) to PHP server (Laravel)

I have been messing around with superagent in my project lately and ended up in the road block. I'm trying to send files via ajax to my Laravel PHP, but I can't get anything on the server side. I am using superspy attachment method with no success.

Javascript (ES6)

createProject(input) {

    Request.post(domain + '/projects')
        .withCredentials()
        .field('project', input.project)
          // Truncated for brevity
        .attach('image', input.image)
        .end(function (err, res) {
          // Do something

        }.bind(this));
}

      

When I validate the resulting data based on PHP, I get an array of everything except the posted file.

Any help is appreciated!

0


source to share


1 answer


You can send the file via superagent

using the method send

.

createProject(input) {

  Request.post(domain + '/projects')
    .withCredentials()
    .query({'project': input.project})
    .send(input.file)
    .end(function (err, res) {
      // Do something

  }.bind(this));
}

      



Note that this input.file

is an instance of File .

0


source







All Articles