Hi,
How can upload a file via REST API to gravity forms?
Hello. My colleague @richardw8k recently answered this question for someone; I’m not sure if it was for you or not? I will share his response here for the benefit of others:
File upload support was added in REST API v2, but only for the standard file upload field with the multi file feature disabled. The standard JS example from the postman code generator shows how a file can be uploaded by passing the file path to the FormData API.
var form = new FormData();
form.append("input_1", "a text field");
form.append("input_2", "/pah/to/file.png");
var settings = {
"async": true,
"crossDomain": true,
"url": "https://domain.local/wp-json/gf/v2/forms/93/submissions",
"method": "POST",
"headers": {
"Content-Type": "application/x-www-form-urlencoded",
"cache-control": "no-cache",
"Postman-Token": ""
},
"processData": false,
"contentType": false,
"mimeType": "multipart/form-data",
"data": form
}
$.ajax(settings).done(function (response) {
console.log(response);
});
If you need to send the file as a base64 data URI you would need to use some custom code process that data e.g. https://gist.github.com/richardW8k/17d8ee4285d1c0c82125262b9b4348ec
That example saves the file to the tmp location for the form in question and adds the file name to the gform_uploaded_files input which is where the plugin stores the file names of files uploaded by the single file upload fields during paging and form validation failures.
@chrishajer Thanks for your reply. Any insights on we can upload multiple files?
It will be really helpful if Gravity Forms Team can upload a POSTMAN collection to upload multiple files.
The multi-file upload field is not supported by the Gravity Forms REST API. If you need to upload multiple files, you would need to use multiple single file upload fields and handle each of them separately.
Thank you so much for the quick response.
It would be wonderful if you can share a postman collection as a sample.
@bhagwant.banger are you uploading values with a checkbox by chance? Did you know the format that it needs to be passed when using formdata?
I asked the question here as well: How to submit checkbox values through the REST API v2 (what is the correct format)
Hey @rorymheaney ,
-
I used the endpoint:-
/wp-json/gf/v2/forms/{form_id}/submissions -
The checkboxes were passed like this:-
(Considering there is a checkbox field with id 3)
input_3.1 : “First Option”
input_3.2 : “Second Option”
input_3.3 : “Third Option”
Let me know if I can help you further with this.
Regards
Bhagwant
Hi would this still be the case for multi file upload field (still not supported)? for REST API
Hi Joshua. The multi-file upload fields are still not supported by the REST API. If you would like to vote for that feature, please click the blue in the lower left on this page to add a note for our product team:
https://www.gravityforms.com/gravity-forms-roadmap/
Thank you.