Skip to content

Instantly share code, notes, and snippets.

@ngalluzzo
Created January 24, 2017 02:10
Show Gist options
  • Save ngalluzzo/45e461e1fa50270073fd1174cc283a8a to your computer and use it in GitHub Desktop.
Save ngalluzzo/45e461e1fa50270073fd1174cc283a8a to your computer and use it in GitHub Desktop.
$(document).ready(function(){
//this assumes you have a file field in your form with id=image
//when this field is updated, run the function
$('#image').change(function(e){
var file = this.files[0];
var form = new FormData();
form.append('files', file);
$.ajax({
url : "https://api.knack.com/v1/applications/[YOUR APP ID]/assets/image/upload",
headers: {"x-knack-application-id":"YOUR APP ID",
"x-knack-rest-api-key": "YOUR API KEY"},
type: "POST",
cache: false,
contentType: false,
processData: false,
data : form,
success: function(response){
$('.result').html(response.html)
}
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment