File Upload/Check/Download
Mohido opened this issue · 4 comments
Our express server must have an endpoint for submitting tasks (HWs/PTs....). A good start is to check this link: https://attacomsian.com/blog/uploading-files-nodejs-express
.
One main consideration is that the file must be saved in the directory: <uploads>/<username>/<section(task, hw...)>/<filename(task name)>
. NOTE THAT this is a "STATELESS" saving of files and we need to store it in our database rather than the backend container. However, this issue can be handled later. For a "SATEFULL" implementation, refer to this article: https://www.codementor.io/@dhananjaykumar/node-express-for-file-upload-management-with-postgres-and-sequelize-y230no8rc
an example endpoint: POST ourbackendserverdomain.com/sections/upload/task
. Moreover, we need to have a request to get the uploaded file or to query if there is an uploaded file in the system! GET /sections/check/task
and GET /sections/get_file/task
or some similar endpoint. However, they need to be standardized in a way. The standard way I will prefer to do it personally, is GET /<whom this function belongs>/<CRUD operation>/<api function>/{:id}
where the {:id}
is optional. If id is not there, then I assume the call requires a general CRUD
operation on all the entries of that api function
and not a specific function.
@the4t4
Yes, and also to other endpoints such as get/tasks
. Currently, the solution and the task description are sent as text. However, they should be send as files (formally). Another idea is to expand the endpoint so that it takes what type of data it should return through the query. For instance:
tasks/<taskID>/submission
[GET]
Query:
userID = <integer>
solutions/submissions/... = <boolean>
asFile= <boolean>
A text should be returned if asFile
is not given in the query. If asFile
is given, then the backend sends a file instead of the text data.
Note: If it is overcomplicated to send back file and JSON data in the same request. Then, for now, we can settle with sending text back to the frontend, and the frontend displays it if needed. @Abdulla-Alkhulaqui @RealGorandos What do you guys think?
Agree