Skip to content

Instantly share code, notes, and snippets.

@wholypantalones
Last active July 25, 2018 14:36
Show Gist options
  • Save wholypantalones/d4e1fa29fbacc4a8d1258f0c92bc84ee to your computer and use it in GitHub Desktop.
Save wholypantalones/d4e1fa29fbacc4a8d1258f0c92bc84ee to your computer and use it in GitHub Desktop.
Angular 6.x.x multipart form data post
// Completey omit the 'ContentType: multipart/form-data' headers
// const httpUploadOptions = {
// headers: new HttpHeaders({
// 'Content-Type': 'multipart/form-data'
// })
// };
const str = JSON.stringify('your Blob or Array');
const fd = new FormData();
const file = new File([str], 'fileName');
fd.append('file', file);
this.http.put('path/to/url', fd)
.subscribe(
data => this.data = data as any,
err => 'do something with error'
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment