Upload a File to Gravity Forms Via Rest API

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.

© 2008 - 2019. Gravity Forms is a project by Rocketgenius Inc.