0

I am trying to set up a learning system for a uni project and i need the students to be able to upload a PDF of their work to a Table called Assessment Submissions and I need to store the data in one of the rows... I have looked all over and I know you have to use the blob typing but apart from that I am scuppered (the column in the table is called fileUpload). Any help would be really useful!! I have attached some code that i am working on

Assessment Models

exports.submitAssessment = async (pupilID, AssesmentsID, Submission,myfile) => {
    


    const assessment = { pupilID, AssesmentsID, Submission, fileUploads:myfile}
    var database = await require('../dbConfig');
     await database.query('INSERT INTO AssessmentSubmissions SET ?', assessment)
}

Assessments Controller

exports.submitAssessment = async (req, res) => 
{   
    console.log(req.originalUrl + " POST Received with query: ", session.pupilID, req.params.AssessmentsID, req.body.Submission)
    const submission = await assessments.submitAssessment(session.pupilID, req.params.AssessmentsID, req.body.Submission,req.body.myfile)
    res.send(submission)
}

Assessment Submission View

<form class="" method="POST" action="{{{req.params.AssessmentsID}}}/submit-assessment">
    <label for="Answer">Answer</label><br>
    <textarea name="Submission"></textarea>
    <label for="myfile">Select a file:</label>
    <input type="file" id="myfile" name="myfile"><br><br>
    <input type="submit" />
</form>

1 Answer 1

1

Pdf is a file, the best way to store a file is in a file system like an image or a video, you can event compress it as a zip file to gain more storage.

All you need is to store a reference of the pdf file, like an id or a unique name, in your database and get the file from your file system when ever you need it.

Here is a tutorial I found just by googling "tutorial node js store files"

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.