Spaces:
Paused
Paused
Download src/utils/storageUtils.js from ismizo/tenderizer: direct link, hf CLI and curl.
- Browser
- Download file 1.19 kB
-
https://huggingface.co/spaces/ismizo/tenderizer/resolve/main/src/utils/storageUtils.js
- Command line
-
hf download hf://spaces/ismizo/tenderizer/src/utils/storageUtils.js
-
curl -L -o storageUtils.js https://huggingface.co/spaces/ismizo/tenderizer/resolve/main/src/utils/storageUtils.js
1.19 kB
| import { PutObjectCommand, GetObjectCommand } from '@aws-sdk/client-s3'; | |
| //import { getSignedUrl } from "@aws-sdk/s3-request-presigner"; // Optional if we want signed URLs | |
| import r2Client from '../config/storage.js'; | |
| const BUCKET_NAME = process.env.R2_BUCKET_NAME; | |
| // Upload File to R2 | |
| export const uploadToR2 = async (fileBuffer, fileName, mimeType) => { | |
| const key = `tenders/${Date.now()}_${fileName.replace(/\s+/g, '_')}`; | |
| const command = new PutObjectCommand({ | |
| Bucket: BUCKET_NAME, | |
| Key: key, | |
| Body: fileBuffer, | |
| ContentType: mimeType | |
| }); | |
| await r2Client.send(command); | |
| return key; | |
| }; | |
| // Get File Stream from R2 | |
| export const getFileStream = async (key) => { | |
| const command = new GetObjectCommand({ | |
| Bucket: BUCKET_NAME, | |
| Key: key | |
| }); | |
| const response = await r2Client.send(command); | |
| return response.Body; | |
| }; | |
| // Get Full Object from R2 (Modified to return full response) | |
| export const getFileObject = async (key) => { | |
| const command = new GetObjectCommand({ | |
| Bucket: BUCKET_NAME, | |
| Key: key | |
| }); | |
| return await r2Client.send(command); | |
| }; | |