Skip to content

Conversation

@shashank-madan
Copy link
Contributor

Description

Upon successful upload or link submission, the system performs the following:

  • Updates the backend to save the file (in Azure Blob Storage).
  • Changes the corresponding task’s status to Submitted.
  • Records the submission timestamp and supports versioning for multiple uploads.

Features

  • Support uploading files of specific allowed types (e.g., PDF, DOCX, TXT, images).
  • Enforce file size limits (e.g., max 10 MB).
  • Validate upload type and size on frontend and backend with user-friendly error messages.

Input Specifications

Accepts:

  • task_id (required)
  • student_id (from authenticated session or explicitly)
  • Either file (multipart/form-data) OR link (string)

Validations

  • File type whitelist: e.g., .pdf, .docx, .txt, .png, .jpg
  • Max file size limit: e.g., 10 MB
  • Link format: Proper URL format validation

Logic Flow

On Success:

  • Save uploaded file to secure storage (Azure Blob Storage).
  • Store file URL or submitted link in the submission_link field of the student's task record.
  • Update status to "Submitted" and record submission_time.

On Failure:

  • Return meaningful error messages to users (e.g., “Unsupported file type”, “File exceeds maximum size”, “Invalid URL format”).

Main Changes Explained

  • Updated upload functionality to upload to Azure Blob Storage instead of S3.

How to Test

Prerequisites: Azure Blob Storage Setup (Free Tier)

1. Create Azure Account

  1. Go to https://azure.microsoft.com/free.
  2. Sign up for a free Azure account (includes $200 credit for 30 days + free services for 12 months).
    • Note: You'll need a credit card for verification, but won't be charged for free tier usage.

2. Create Storage Account

  1. Log into the Azure Portal.
  2. Click Create a resource → Search for Storage account.
  3. Click Create.
  4. Fill in the details:
    • Subscription: Select your free subscription.
    • Resource group: Create new (e.g., hgn-resources).
    • Storage account name: Choose a unique name (e.g., hgnstorage123).
    • Region: Select the one closest to you.
    • Performance: Standard.
    • Redundancy: LRS (Locally-redundant storage) - cheapest option.
    • Advanced Tab: Check "Allow enabling anonymous access on individual containers".
  5. Click Review + CreateCreate.

3. Create Blob Container

  1. Once the storage account is created, go to the resource.
  2. In the left menu, click Containers under Data storage.
  3. Click + Container.
  4. Enter container name (e.g., student-files).
  5. Public access level: Select Blob (allow anonymous read access for blobs only).
  6. Click Create.

4. Get Connection String

  1. In your storage account, go to Access keys (left menu under Security + networking).
  2. Click Show keys.
  3. Copy the Connection string from key1 or key2.

5. Update .env File
Add these two variables to your .env file (replace the connection string with the one copied in Step 4):

AZURE_STORAGE_CONNECTION_STRING=DefaultEndpointsProtocol=https;AccountName=your-accountname;AccountKey=your-account-key;EndpointSuffix=core.windows.net
AZURE_STORAGE_CONTAINER_NAME=student-files

Execution Steps

1. Setup Local Environment

  1. Check into the current branch.
  2. Run the following commands to build and start the PR locally:
    npm install
    npm run build
    npm start
  3. Open Postman.

2. Authentication

  1. Get your auth token. Send a POST request to http://localhost:4500/api/login with the body:
    {
      "email": "",
      "password": ""
    }
  2. Note: For all subsequent requests, add an authorization header with the token received from the above step.

3. Get User ID

  1. Send a GET request to:
    http://localhost:4500/api/userProfile/singleName/{your first name or last name here}
  2. Look at the result and note down the _id (User ID) of your current login account.

4. Create a Task

  1. Send a POST request to http://localhost:4500/api/education-tasks.
  2. Body Example:
    {
      "name": "Test task",
      "status": "assigned",
      "lessonPlanId": "68ed6e6e746d9b633a6158f2",
      "atomIds": ["68def3a5f0844c6916607a9c"],
      "type": "write",
      "dueAt": "2025-10-24T00:00:00.000+00:00",
      "studentId": "{Your_User_ID_Here}"
    }
  3. Note down the returned Task ID.

5. Test API: Upload a File

  1. Send a POST request to:
    http://localhost:4500/api/student/tasks/{your_task_id}/upload
  2. In the Body tab, select form-data.
  3. Key: file (select "File" type from the dropdown on the right of the key field).
  4. Value: Upload a sample file.
  5. Click Send.

6. Verify Success

  1. Send a GET request to:
    http://localhost:4500/api/education-tasks/{your_task_id}
  2. Confirm the following:
    • status has changed to completed.
    • completedAt is updated to today's date.
    • The link to your file is successfully added to uploadUrls.

7. Cleanup

  1. Delete all files uploaded to your Azure storage container.
  2. Delete the created storage containers and storage account in the Azure Portal.

Screenshots or videos of changes:

Postman.2025-11-27.10-41-55.mp4
Screenshot 2025-11-27 104339

@one-community one-community added the High Priority - Please Review First This is an important PR we'd like to get merged as soon as possible label Dec 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

High Priority - Please Review First This is an important PR we'd like to get merged as soon as possible

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants