Browse Source

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

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

Loading…
Cancel
Save