1

I'm trying to send a blob to my server, but it wont work. I'm using the doctemplater library which creates a Blob. This blob is correct because I'm able to save to local file (with saveAs(...)). But now I need to transfer this file to my server too.

let out = doc.getZip().generate({
    type: 'blob',
    mimeType: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
});

So I'm trying

const data = {
    name: "test,
    content: out
}

this.http.post<any[]>(this.path, data).pipe(
    catchError((err: HttpErrorResponse) => {
        // ...
    })
);

The problem is that data['out'] is always empty on server side. So how can I send a blob to the server?

1
  • What do you mean by data['out'] is empty? Commented Sep 1, 2020 at 8:14

3 Answers 3

3

Try using FormData like this:

const formData = new FormData();
formData.append(name, value, filename);

For more information visit this link.

Sign up to request clarification or add additional context in comments.

Comments

0

In your service file create a post method

updateDistrictLogo(formdata: FormData): Observable<any> {
  return this.http.post<any>(
    this.constantService.getUrl(your API URL), formdata,
);
}

in your componen.ts file create a instance of service in constructor

   constructor(private ContactService: ContactInformationService) {}

then create a method and call api

 updatefile() {
  const formdata = new FormData();
        formdata.append("file", blob);
        this.ContactService.updateDistrictLogo(formdata).subscribe(
            success => {
               console.log(success);
            },
            error => {
           console.log(error);
         }
        );
   }

Comments

-1

try with

this.http.post<any[]>(path, data, { responseType: 'blob'})    

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.