Skip to content

Julia - Upload Functionality for Write Tasks Backend#1868

Merged
one-community merged 5 commits intodevelopmentfrom
julia-create-backend-for-upload-file
Nov 23, 2025
Merged

Julia - Upload Functionality for Write Tasks Backend#1868
one-community merged 5 commits intodevelopmentfrom
julia-create-backend-for-upload-file

Conversation

@JuliaHa0902
Copy link
Copy Markdown
Contributor

@JuliaHa0902 JuliaHa0902 commented Oct 31, 2025

Description

Upon successful upload or link submission:
◦ Update backend to save the file (in S3 or server folder) or store the submitted link.
◦ Change the corresponding task’s status to Submitted.
◦ Record submission timestamp and support 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.
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)
• Proper URL format for links
On success:
• Save uploaded file to secure storage (S3 or server directory).
• 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”).

Related PRS (if any):

This frontend PR is related to the #XXX backend PR.
To test this backend PR you need to checkout the #XXX frontend PR.

Main changes explained:

  • Add the POST method to the URL /api/student/tasks/:id/upload
  • The body can take a file or
    {
    url: url_link_here
    }
    After submitting, the file will be uploaded to AWS S3. Links will be saved to our MongoDB. Status and completedDate of the task will be updated

How to test:

Requirements

In order to test this branch, you have to get access to an AWS S3

Screenshot 2025-10-31 110555 - In General Purpose bucket, click on Create bucket - Create a bucket - In the search bar, go to IAM service Screenshot 2025-10-31 111200 - In User tab, create a user. In permission, choose Attach policy directly. Screenshot 2025-10-31 111800 - In Permission policies, choose S3 full access, then click on create user Screenshot 2025-10-31 111855
  • Click on the user created. Click on "create Access Key." Save the access key and secret access key to your .env
  • In .env file, add the following variable
    AWS_ACCESS_KEY_ID={Your access key}
    AWS_SECRET_ACCESS_KEY={Your secret access key}
    AWS_REGION={Your region} (See on the navbar top right side)
    S3_BUCKET_NAME={The bucket you created}

Test

  1. check into current branch
  2. Add the env variable for AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION, S3_BUCKET_NAME
  3. do npm install, 'npm run build' and ... to run this PR locally
  4. Clear site data/cache
  5. Open Postman
  6. Login using admin or owner

Get your user id:
10. Send a GET request to http://localhost:4500/api/userProfile/singleName/{your first name or last name here}
11. Look at the result and note down the user Id of your current login account

Create a task
13. Send POST request to http://localhost:4500/api/education-tasks
example body {
"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}
}
Note down your task ID

**Test my API - upload a file
14. Send a POST request to http://localhost:4500/api/student/tasks/{your_task_id}/upload
In the body, choose form-data.
In key field, choose file
In value, upload a file
Click Send
15. Send a GET request to http://localhost:4500/api/education-tasks/{your_task_id}
16. Confirm that status has changed to completed, completedAt is updated to today, and the link to your file is added to uploadUrls

**Test my API - upload an url
18. Send a POST request to http://localhost:4500/api/student/tasks/{your_task_id}/upload
body {
"url": "A valid URL here"
}
Click Send
19. Send a GET request to http://localhost:4500/api/education-tasks/{your_task_id}
20. Confirm that status has changed to completed, completedAt is updated to today, and the link to your file is added to uploadUrls

Cleanup

  • Delete all the files uploaded to your AWS S3
  • Inactive or delete your Access key in AWS

Screenshots or videos of changes:

How.to.test.PR.mp4

Note:

Include the information the reviewers need to know.

@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 Nov 20, 2025
Copy link
Copy Markdown

@Anusha-Gali Anusha-Gali left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Julia,

I have reviewed your PR locally and have followed the exact steps you have mentioned and was able to create the AWS S3 bucket with IAM permissions as well as I was able to run all the API calls.
Screenshot 2025-11-20 at 6 20 51 PM
Screenshot 2025-11-20 at 6 21 07 PM
Screenshot 2025-11-20 at 6 21 12 PM
Screenshot 2025-11-20 at 6 21 18 PM
Screenshot 2025-11-20 at 6 21 27 PM
Screenshot 2025-11-20 at 6 21 33 PM
Screenshot 2025-11-20 at 6 25 24 PM
Screenshot 2025-11-20 at 6 25 37 PM
Screenshot 2025-11-20 at 6 26 04 PM

@one-community
Copy link
Copy Markdown
Member

Thank you all, merging!

@one-community one-community merged commit 6bfed52 into development Nov 23, 2025
1 check passed
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