|
|
@ -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, |
|
|
|
|
|
|
|
// ContentType: file.mimetype,
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
|
|
|
|
// Configure the file stream and obtain the upload parameters
|
|
|
|
|
|
|
|
const fileStream = fs.createReadStream(file.path); |
|
|
|
const fileStream = fs.createReadStream(file.path); |
|
|
|
fileStream.on('error', (err) => { |
|
|
|
// upload using stream
|
|
|
|
console.log('File Error', err); |
|
|
|
return this.fileCreateByStream(key, fileStream); |
|
|
|
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
|
|
|
|