-
Notifications
You must be signed in to change notification settings - Fork 85
Description
🎯 Goal
Implement a backend utility that uploads image files to Azure Blob Storage and returns a public HTTPS URL.
This service will later be used by /upload-photo and other backend routes.
Note: For this Issue your Github Edu Pack must be enabled, as it will be used with the Azure for Students ,where we will use the Azure blob Storage Service.
📝 Task Description
All work for this issue must be done inside:
/backend/utils/azure.js and in /backend/testing/test_azure_upload.js
You will:
1. Install Azure SDK
Run the following:
npm install @azure/storage-blobThis library enables communication with Azure Blob Storage services.
2. Create or Access the photos Container
Using the connection string from .env, initialize:
- BlobServiceClient
- ContainerClient → container named photos
If the container does not exist, your code must create it. Name the container SnapMap_Blob.
3. Write the Upload Function
Create:
async function uploadToAzure(buffer, fileName)The function must:
- Accept a file buffer and a file name
- Upload the buffer to Azure Blob Storage inside the
photoscontainer - Return the public HTTPS URL of the uploaded image
Example Outline:
const { BlobServiceClient } = require("@azure/storage-blob");
async function uploadToAzure(buffer, fileName) {
const blobServiceClient = BlobServiceClient.fromConnectionString(
process.env.AZURE_STORAGE_CONNECTION
);
const containerClient = blobServiceClient.getContainerClient("photos");
await containerClient.createIfNotExists();
const blockBlobClient = containerClient.getBlockBlobClient(fileName);
await blockBlobClient.uploadData(buffer);
return blockBlobClient.url;
}
module.exports = uploadToAzure;4. Testing
Inside the /backend/testing/test_azure_upload.js, write a basic testing code where we can have some image in the same folder, and we can upload that image to the container using the fucntion uploadToAzure() written above. The returned URL will be saved inside a IMG_URLS.txt in the same folder.
📤 PR Submission
A successful PR should demonstrate:
File appears inside Azure Storage
You should be able to see the uploaded image under the photos container.
Attach the screenshot of this
Function returns a valid HTTPS URL
Example:
https://<your-storage>.blob.core.windows.net/photos/<fileName>
Attach screenshot of the successfull upload of images in the blob container and some already uploaded images URL inside the IMG_URL.txt , that i can access.