Skip to content

Instantly share code, notes, and snippets.

@AndreasDickow
Created August 9, 2017 10:07
Show Gist options
  • Save AndreasDickow/9d5fcd2c608b4726d16dda37cc880a7b to your computer and use it in GitHub Desktop.
Save AndreasDickow/9d5fcd2c608b4726d16dda37cc880a7b to your computer and use it in GitHub Desktop.
Ionic2 File Upload to Django Rest Framework
let options: FileUploadOptions = {
fileKey: 'image',
fileName: this.result.substr(this.result.lastIndexOf('/') + 1),
mimeType : 'image/jpeg',
httpMethod : "PUT",
headers: {Authorization: this._variableService.getToken(),}
}
const fileTransfer: FileTransferObject = this.transfer.create();
fileTransfer.upload(this.result, encodeURI(this._variableService.getBaseUrl() + '/api/v2/profile_image/'+this.result.substr(this.result.lastIndexOf('/') + 1)), options)
.then((data) => {
console.log(data);
}, (err) => {
console.log(err);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment