Skip to content

Commit

Permalink
fix storage
Browse files Browse the repository at this point in the history
  • Loading branch information
andrzahadlx committed Nov 7, 2024
1 parent 8f0d328 commit 7f31b88
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ export class StorageService {
async uploadToS3(file: File, bucket: string, key: string) {
if (!this.s3Client) throw new Error("S3 client not initialized");

const arrayBuffer = await file.arrayBuffer();
const buffer = Buffer.from(arrayBuffer);

const command = new PutObjectCommand({
Bucket: bucket,
Key: key,
Body: await file.arrayBuffer(),
Body: buffer,
ContentType: file.type,
});

Expand All @@ -28,10 +31,13 @@ export class StorageService {
const containerClient = this.blobClient.getContainerClient(containerName);
const blockBlobClient = containerClient.getBlockBlobClient(blobName);

return blockBlobClient.uploadData(await file.arrayBuffer(), {
const arrayBuffer = await file.arrayBuffer();
const buffer = Buffer.from(arrayBuffer);

return blockBlobClient.uploadData(buffer, {
blobHTTPHeaders: { blobContentType: file.type },
});
}
}

export const storageService = new StorageService();
export const storageService = new StorageService();

0 comments on commit 7f31b88

Please sign in to comment.