我正在嘗試在記憶體中創建一個 zip 檔案(使用 TypeScript),然后將其存盤在 AWS S3 存盤桶中。輸入是純文本 CSV 字串(資料)。
我不確定我做錯了什么,因為下載檔案時在 s3 中創建的 zip 檔案不可讀。
編碼:
const zip = new AdmZip();
zip.addFile('tmp.txt', Buffer.from(data, 'utf-8'));
const zipData = await zip.toBufferPromise();
try {
const now = dayjs().format('YYYYMMDDTHHmmss');
const fileName = `Feedback-${now}`;
await this._storageService.saveFile(zipData.toString('binary'), 'sprintFeedback', fileName);
uj5u.com熱心網友回復:
解決方案很簡單:只需將以下行的結果發送到您的 s3 存盤桶,并將其存盤為適當的 zip 檔案;
const zipData: Buffer = await zip.toBufferPromise();
const command = new PutObjectCommand({
Bucket: bucketName,
Body: zipData,
Key: fileName,
});
await this._s3Client.send(command);
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/463943.html
