Browse Source

feat: fileCreateByStream for S3 (#9003)

pull/9006/head
Mert E 5 months ago committed by GitHub
parent
commit
7bedda11c3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 54
      packages/nocodb/src/plugins/s3/S3.ts

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

@ -25,31 +25,10 @@ export default class S3 implements IStorageAdapterV2 {
} }
async fileCreate(key: string, file: XcFile): Promise<any> { async fileCreate(key: string, file: XcFile): Promise<any> {
const uploadParams: any = { // create file stream
...this.defaultParams, const fileStream = fs.createReadStream(file.path);
// ContentType: file.mimetype, // upload using stream
}; return this.fileCreateByStream(key, fileStream);
return new Promise((resolve, reject) => {
// Configure the file stream and obtain the upload parameters
const fileStream = fs.createReadStream(file.path);
fileStream.on('error', (err) => {
console.log('File Error', err);
reject(err);
});
uploadParams.Body = fileStream;
uploadParams.Key = key;
// call S3 to retrieve upload file to specified bucket
// call S3 to retrieve upload file to specified bucket
this.upload(uploadParams)
.then((data) => {
resolve(data);
})
.catch((err) => {
reject(err);
});
});
} }
async fileCreateByUrl(key: string, url: string): Promise<any> { async fileCreateByUrl(key: string, url: string): Promise<any> {
@ -75,9 +54,28 @@ export default class S3 implements IStorageAdapterV2 {
} }
} }
// TODO - implement fileCreateByStream(key: string, stream: Readable): Promise<void> {
fileCreateByStream(_key: string, _stream: Readable): Promise<void> { const uploadParams: any = {
return Promise.resolve(undefined); ...this.defaultParams,
};
return new Promise((resolve, reject) => {
stream.on('error', (err) => {
console.log('File Error', err);
reject(err);
});
uploadParams.Body = stream;
uploadParams.Key = key;
// call S3 to upload file to specified bucket
this.upload(uploadParams)
.then((data) => {
resolve(data);
})
.catch((err) => {
reject(err);
});
});
} }
// TODO - implement // TODO - implement

Loading…
Cancel
Save