Upload file to /media or upload to ACF file field using REST API Wordpress

Viewed 32

I have a HTML form. When I submit it, I need it to create a post in Wordpress and fill his fields. I did it for text fields, but I have one file field that I couldn't fill. The field uses ACF type file.

I found out that I can upload my file to /media, because to use update_field(name, value, post_id) for a file, I need to put the attach_id in the value space. But I couldn't upload my file to /media.

This is how my file looks like after I take it from the form:

And this is how it looks like when I send it to PHP with FormData and return it as a JSON: enter image description here

This is my PHP code, which tries to upload the file to wp-json/wp/v2/media

enter image description here

And it is doing fine, but it says the content I'm trying to upload is empty. This is the response I receive

code: "rest_upload_no_data"
data: {status: 400}
message: "No data provided."

I think might be another way of threating files from forms in PHP, but I couldn't figure out. Can you guys help me pls?

Thank you!!

0 Answers
Related