从第三方api,我得到了这种类型的数据
%PDF-1.7 %���� 2093 0 obj <> endobj 2240 0 obj <>/Filter/FlateDecode/ID[(\204\240\33\17\372\324FC\221_B\326\226\7\374\206) (\204\240\33\17\372\324FC\221_B\326\226\7\374\206)]/Index[2093 148]/Info 2092 0 R/Length 164/Prev 1150275/Root 2094 0 R/Size 2241/Type/XRef/W[1 3 1]>> stream x�cbd```b`` �� ���d4�6`�D2��`�L.��������`R���LZ�E������S�`"�V!،�`v���dbgc����0�`?ƃH��`�<0�DJ�lg|2�q��?u�^�Qr������w�|&�g&��ŕ��� endstream endobj startxref 0 %%EOF 2094 0 obj <>/Metadata 1312 0 R/Pages 1566 0 R/StructTreeRoot 1569 0 R/Type/Catalog/ViewerPreferences 2140 0 R>> endobj 2238 0 obj <> stream
这是一个pdf文件,我想上传的s3,这里是代码
const response = await axios.get(url, options);
const file = { originalname: `${docName}.pdf`, buffer: response.data };
await this.s3Service.upload(file, `${S3_BASE_PATH.DOCS}/ENQ_${enquiryDocDto.enquiryId}`);
和S3业务上的上传方法
async upload(file, basePath: string): Promise<string> {
const fileName = this._getRandomFileName(file)
const bucketFileKey = `${basePath}/${fileName}`;
const params: AWS.S3.PutObjectRequest = {
Bucket: this.bucketName,
Key: bucketFileKey,
Body: file.buffer
};
this.logger.log(`Uploading ${bucketFileKey}`);
await this.s3.putObject(params).promise();
this.logger.log(`Uploaded ${bucketFileKey}`);
return bucketFileKey;
}
从api,我得到这个pdf数据的工作在postman,和相同的数据,它返回和保存响应从postman它创建一个有效的pdf.
但通过代码,它没有正确上传
我甚至试着创建这样的缓冲区
const buffer = Buffer.from(response.data, "utf-8")
我试过"binary"
种,但没有成功.
当我直接从我的nodejs上传时,
所以我试着把它转换成Buffer
,但转换成Uint8Array
UPdate1
const options = {
headers: { accept: "*/*", authorization: `Bearer ${accessToken}`, 'Content-Type': 'application/octet-stream' }
};
我试着删除内容类型,接受以及,更改接受到申请人/pdf以及
甚至try 了这个
fs.writeFileSync("A.pdf", Buffer.from(response.data));
fs.writeFileSync("B.pdf", Buffer.from(response.data, "binary"));
fs.writeFileSync("C.pdf", Buffer.from(response.data, "utf-8"));
fs.writeFileSync("D.pdf", response.data);
仍然是同一个问题