Browse Source

fix: S3

nc-fix/at-attachments
mertmit 10 months ago
parent
commit
0c9f916d6f
  1. 65
      packages/nocodb/src/plugins/s3/S3.ts

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

@ -56,27 +56,23 @@ export default class S3 implements IStorageAdapterV2 {
const uploadParams: any = { const uploadParams: any = {
...this.defaultParams, ...this.defaultParams,
}; };
return new Promise((resolve, reject) => {
axios try {
.get(url, { const response = await axios.get(url, {
httpAgent: useAgent(url, { stopPortScanningByUrlRedirection: true }), httpAgent: useAgent(url, { stopPortScanningByUrlRedirection: true }),
httpsAgent: useAgent(url, { stopPortScanningByUrlRedirection: true }), httpsAgent: useAgent(url, { stopPortScanningByUrlRedirection: true }),
responseType: 'stream', responseType: 'stream',
}) });
.then((response) => {
uploadParams.Body = response.data; uploadParams.Body = response.data;
uploadParams.Key = key; uploadParams.Key = key;
uploadParams.ContentType = response.headers['content-type']; uploadParams.ContentType = response.headers['content-type'];
// call S3 to retrieve upload file to specified bucket const data = await this.upload(uploadParams);
this.upload(uploadParams).then((data) => { return data;
resolve(data); } catch (error) {
}); throw error;
}) }
.catch((error) => {
reject(error);
});
});
} }
// TODO - implement // TODO - implement
@ -161,26 +157,23 @@ export default class S3 implements IStorageAdapterV2 {
} }
private async upload(uploadParams): Promise<any> { private async upload(uploadParams): Promise<any> {
return new Promise((resolve, reject) => { try {
// call S3 to retrieve upload file to specified bucket // call S3 to retrieve upload file to specified bucket
const upload = new Upload({ const upload = new Upload({
client: this.s3Client, client: this.s3Client,
params: { ...this.defaultParams, ...uploadParams }, params: { ...this.defaultParams, ...uploadParams },
}); });
upload const data = await upload.done();
.done()
.then((data) => { if (data) {
if (data) { return `https://${this.input.bucket}.s3.${this.input.region}.amazonaws.com/${uploadParams.Key}`;
resolve( } else {
`https://${this.input.bucket}.s3.${this.input.region}.amazonaws.com/${uploadParams.Key}`, throw new Error('Upload failed or no data returned.');
); }
} } catch (error) {
}) console.error(error);
.catch((err) => { throw error;
console.error(err); }
reject(err);
});
});
} }
} }

Loading…
Cancel
Save