Skip to content

Instantly share code, notes, and snippets.

@resba
Created October 9, 2025 17:00
Show Gist options
  • Select an option

  • Save resba/ed12059b7986aa24fde3f352de39bed2 to your computer and use it in GitHub Desktop.

Select an option

Save resba/ed12059b7986aa24fde3f352de39bed2 to your computer and use it in GitHub Desktop.
Post with Angular multipart data
postFile(uri: string, data: any, file: any = null): Observable<any>{
if(file) {
let t = data;
let formData: FormData = new FormData();
console.log(file);
formData.append('file', file.originFileObj, file.name);
Object.keys(data).forEach((key)=>{formData.append(key,data[key])});
data = formData;
}
return this.rest.post(uri, data, {headers: this.headers, withCredentials: true});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment