Skip to content
Advertisement

How do I send an image to a PHP API using VueJS?

I am trying to send an object which contains an image using Vue to a PHP API but honestly I don’t know how, I have my form

JavaScript

and the getImage() like this

JavaScript

}

JavaScript

I don’t know how to access this image in my PHP API and upload it to database. I tried accessing $_FILES but it’s an empty array

Sorry seems the problem is that I am sending some other data too and not only the formData

Advertisement

Answer

if you want to send an image to an api.

  1. You form should specify the type de data you must send for

    your form. you should add this.

    JavaScript

In your script you need to set this methods

JavaScript

Please check the docs

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement