尝试从nodejs和aws-sdk上传40k个文件到s3,我确实验证了所有代码都运行良好,最多5800条记录,但失败后,其余的文件无法上传,有人能帮我解释为什么会发生这种情况吗,或者我必须使用其他方法,或者我需要更新我的代码?
以下是我的代码
public static convertClobAndUploadToS3(allClobAttachments: Array<RfAttachment>):
Promise<FileConvertS3UploadResponse> {
return new Promise(async (resolve, reject) => {
const fileConvertResp: FileConvertS3UploadResponse = { processed: [], unprocessed: [] };
for (let i = 0; i < allClobAttachments.length; i++) {
const rfAttachment = allClobAttachments[i];
const mainFileBufferFormat: Buffer = Buffer.from(rfAttachment.CLOB);
const path = CONST.S3.PATH.MAIN_FILE;
const fileName = rfAttachment.RF_ID + CONST.S3.EXT.MAIN_FILE;
// upload only single file to s3 at a time and returns url
const url = await GFIUtils.uploadFileToS3(config, fileName, mainFileBufferFormat, path);
url ? fileConvertResp.processed.push({ RFID: rfAttachment.RF_ID, url, rfAttachment })
: fileConvertResp.unprocessed.push(rfAttachment.RF_ID);
if (fileConvertResp.processed.length === allClobAttachments.length) {
logger.info(`CLOB STAGE::: All clob successfully uploaded!!! TOTAL CLOB:::${allClobAttachments.length}`);
return resolve(fileConvertResp);
} else if (fileConvertResp.unprocessed.length + fileConvertResp.processed.length
=== allClobAttachments.length) {
logger.info(`allClobAttachments::: ${allClobAttachments.length}`);
logger.info(`processed::: ${fileConvertResp.processed.length}`);
logger.info(`unprocessed::: ${fileConvertResp.unprocessed.length}`);
return reject(fileConvertResp);
} else { continue; }
}
});
}发布于 2020-02-20 22:44:06
而不是这样做,而是采取更安全的方法,并使用aws cli打开一个子流程。
使用aws s3 sync或copy命令执行此操作。
它将比在for循环中调用这样的暴力破解方法快得多,并且具有更多的防故障能力。
如果所有文件都不在单个或某个有限数量的目录中。您应该生成要上载的文件的路径列表。将该文本文件写入磁盘。使用aws cli使用文本文件中的路径进行上载或下载。
https://stackoverflow.com/questions/60322193
复制相似问题