HttpResponse <blob>到UInt8Array返回未定义

时间:2019-03-28 13:35:58

标签: angular typescript

我从Spring Boot服务接收到一个Blob,我必须将其转换为UInt8Array。使用以下代码,我得到未定义的结果。我做错了什么?

comparePdfDiff() {
        let responseBlob = null;
        let responseFile = null;
        console.log('Submitted PDF Diff');
        const formModel = this.prepareSave();
        this.loading = true;
        console.log('Formmodel: ', formModel);
        this.http.post('http://localhost:8080/pdfdiffLocal', formModel, {observe: 'response', responseType: 'blob'})
            .subscribe(response => {
                console.log('response: ', response.body);
                responseBlob = response.body;
                responseFile = this.blobToFile(responseBlob, 'result.pdf');
                this.comparejobdataService.pdfFile = responseFile;
                this.router.navigate(['/pdfcompare']);
            });
        setTimeout(() => {
            this.loading = false;
        }, 10000);
    }

    blobToFile(theBlob: HttpResponse<Blob>, fileName: string) {
        const fileReader = new FileReader();
        const b: any = theBlob;
        b.lastModifiedDate = new Date();
        b.name = fileName;

        console.log(b);
        const returnValue = fileReader.readAsArrayBuffer(b);

        return returnValue;
    }

感谢您的帮助!

0 个答案:

没有答案