Browse Source

fix(s3): use stream to upload via url --force--

pull/7018/head
mertmit 1 year ago
parent
commit
cfcdb895b0
  1. 12
      packages/nocodb/src/plugins/s3/S3.ts

12
packages/nocodb/src/plugins/s3/S3.ts

@ -2,6 +2,7 @@ import fs from 'fs';
import { promisify } from 'util';
import { GetObjectCommand, S3 as S3Client } from '@aws-sdk/client-s3';
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
import { Upload } from '@aws-sdk/lib-storage';
import axios from 'axios';
import { useAgent } from 'request-filtering-agent';
import type { IStorageAdapterV2, XcFile } from 'nc-plugin';
@ -60,7 +61,7 @@ export default class S3 implements IStorageAdapterV2 {
.get(url, {
httpAgent: useAgent(url, { stopPortScanningByUrlRedirection: true }),
httpsAgent: useAgent(url, { stopPortScanningByUrlRedirection: true }),
responseType: 'arraybuffer',
responseType: 'stream',
})
.then((response) => {
uploadParams.Body = response.data;
@ -162,8 +163,13 @@ export default class S3 implements IStorageAdapterV2 {
private async upload(uploadParams): Promise<any> {
return new Promise((resolve, reject) => {
// call S3 to retrieve upload file to specified bucket
this.s3Client
.putObject({ ...this.defaultParams, ...uploadParams })
const upload = new Upload({
client: this.s3Client,
params: { ...this.defaultParams, ...uploadParams },
});
upload
.done()
.then((data) => {
if (data) {
resolve(

Loading…
Cancel
Save