export async function upload()

in src/lib/storage.ts [42:69]


export async function upload(
	source: string,
	filename: string | Filename,
	folder?: S3Folder,
): Promise<S3UploadResponse> {
	const outputLocation = getFilename(filename);
	const bucket = await getBucket();
	const key = folder ? `${folder.prefix}${outputLocation}` : outputLocation;
	console.log(`uploading to ${bucket}/${key}`);
	if (!source && key.includes('HOME_DELIVERY')) {
		throw new Error(`${key} should not be empty!`);
	}
	const params = {
		Bucket: bucket,
		Key: key,
		Body: source,
		ServerSideEncryption: 'aws:kms',
	};
	const uploadResponse = await s3.upload(params).promise();
	if (!uploadResponse.Location.includes(key)) {
		throw new Error(
			`${key} should be uploaded to S3. Response: ${util.inspect(
				uploadResponse,
			)}`,
		);
	}
	return uploadResponse;
}