Skip to content

Instantly share code, notes, and snippets.

@orangewolf
Created September 23, 2016 17:50
Show Gist options
  • Save orangewolf/40c628ba72a7defbe659b2937e2dfbdd to your computer and use it in GitHub Desktop.
Save orangewolf/40c628ba72a7defbe659b2937e2dfbdd to your computer and use it in GitHub Desktop.
Formsy File Upload
// in render return
<div>
<Formsy.Form ref="form"
onValidSubmit={this.onSubmit}
onValid={this.props.enableSubmit}
className=""
onInvalid={this.props.disableSubmit}
onChange={this.props.onChange}>
<FormsyFile
id="avatar"
name="avatar"
/>
</Formsy.Form>
</div>
// In onSubmit
onSubmit function(form_data) {
... //setup
var avatarFile = document.getElementById('avatar').files[0];
form_data.append('avatar', avatarFile);
this.serverRequest = $.ajax({
dataType: "json",
method: "POST",
url: url,
data: form_data,
headers: headers,
success: this.submitted,
error: this.errored
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment