I've got a pdf upload section for users on my front end and from there I'd like to send it to an s3 bucket via a micro-service I've created. I have a post route on my micro-service that expects the file but when I send it from the front-end it comes through empty. I'm definitely missing something when it comes to sending the file from the front-end.
export class FileUpload {
private file: File;
constructor(
private service: FileService;
) { }
uploadFile(): void {
const formdata = new FormData();
formdata.append('pdf-file', this.file);
this.service.upload(formdata).subscribe(uploaded => {
console.log(uploaded);
}
}
}
export class FileService {
constructor(private http: HttpClient) { }
public upload(file) {
const headers = new HttpHeaders({'Content-Type': 'multipart/form-data'});
return this.http.post('http://myserviceurl/file', file, {headers: headers}).pipe(
catchError(err => {
return error;
});
}
}
The file variable inside FileUpload
class is the user uploaded pdf file. I'm a bit stuck on working out what I need to do with the file before I can send it via http request. Any help would be greatly appreciated.