#305-fileService #896

Closed
a24noabe wants to merge 13 commits from #305-fileService into team_2_week_5
Collaborator

FileService

Implemented a service allowing users to upload and download files to a server accessible through http.

Endpoints

Endpoint Description Request body
GET /f/{id} Fetch a file None
POST /upload/ Upload a file A file (<1MB)

Adress

The service is available at /api/files/.
/f/{id} expects the uuid of an uploaded file. It returns the file as an inline file instead of as a downloadable.
/upload/ expects a file, currently only .jpg, .jpeg, and .png files are allowed. The allowed file-types, their corresponding HTTP contenttypes, and their file signatures are added in FileService.cs.
Currently, it doesn't check whether a user is logged in, this functionality will be added once the use of tokens is implemented.
In order to test it, i recommend using an html file:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Test</title>
</head>
<body>
    <form action="http://localhost/api/files/upload/" method="post" enctype="multipart/form-data">
        <input type="file" name="image" id="image">
        <button type="submit">Upload</button>
    </form>
</body>
</html>

If the file is uploaded successfully you will get a response like:
image
The name is used at the /f/{id} endpoint, and you can see your image if you go there.

I haven't changed any scripts, so you will have to build the docker image (docker build -t fileservice .) in BoundlessFlowCampus2K\service\fileService\fileService. After you've done this you can run the rebuild script and then the compose file.
Since the endpoints are unsecure, we might have to remove it from the compose file so we don't run it on our server until we have authentication implemented.

# FileService Implemented a service allowing users to upload and download files to a server accessible through http. ## Endpoints | Endpoint | Description | Request body | |---|---|---| | `GET /f/{id}` | Fetch a file | None | | `POST /upload/` | Upload a file | A file (<1MB) | ## Adress The service is available at /api/files/. `/f/{id}` expects the uuid of an uploaded file. It returns the file as an inline file instead of as a downloadable. `/upload/` expects a file, currently only .jpg, .jpeg, and .png files are allowed. The allowed file-types, their corresponding HTTP contenttypes, and their file signatures are added in FileService.cs. Currently, it doesn't check whether a user is logged in, this functionality will be added once the use of tokens is implemented. In order to test it, i recommend using an html file: ```html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Test</title> </head> <body> <form action="http://localhost/api/files/upload/" method="post" enctype="multipart/form-data"> <input type="file" name="image" id="image"> <button type="submit">Upload</button> </form> </body> </html> ``` If the file is uploaded successfully you will get a response like: ![image](/attachments/c1c5146d-037f-4d61-afcf-b76384875fa8) The name is used at the `/f/{id}` endpoint, and you can see your image if you go there. I haven't changed any scripts, so you will have to build the docker image (`docker build -t fileservice .`) in `BoundlessFlowCampus2K\service\fileService\fileService`. After you've done this you can run the rebuild script and then the compose file. Since the endpoints are unsecure, we might have to remove it from the compose file so we don't run it on our server until we have authentication implemented.
3.9 KiB
Ripped straight from tempService.
Nothing done at this point. will get worked on.
The API endpoints now run, but they don't return images or allow for uploading yet. I've implemented some file validation for the upload to make sure that the files uploaded isn't an exe masquerading as an image file. There is also some debugging code in there but it's commented as such for easy removal. There are improvements to be made
lots of code (unreadable)
@ -0,0 +1,34 @@
CREATE DATABASE files; -- Creates and uses the user database for the rest of file
Collaborator

This, or the existing 03-sensors-cron-jobs.sql file, will have to be renamed

This, or the existing 03-sensors-cron-jobs.sql file, will have to be renamed
a22erigr 2026-05-12 08:36:20 +00:00
Collaborator

Everything works well and beautifully.
Every changed file is clean, readable, and populated with comments to explain the logic.

I do wonder if the test file should be filled now?

The only thing to improve is probably in the C# files, all the code is clean but to increase the readability, add at least one empty line between the functions/method, also you will be following the code standards.

Once the code standards are followed, this pull request can be merged.

Everything works well and beautifully. Every changed file is clean, readable, and populated with comments to explain the logic. I do wonder if the test file should be filled now? The only thing to improve is probably in the C# files, all the code is clean but to increase the readability, add at least one empty line between the functions/method, also you will be following the code standards. Once the code standards are followed, this pull request can be merged.
Collaborator

This should not be merged

The developer want to do some changes before merge.

## This should not be merged The developer want to do some changes before merge.
Collaborator

image

![image](/attachments/8163ba6b-f0ed-4941-9725-6d386b98ed31)
7.2 KiB
Collaborator

image

![image](/attachments/a2f3dba4-0a23-4a66-b2b3-3713480b5362)
@ -0,0 +14,4 @@
string DbUser = Environment.GetEnvironmentVariable("DATABASE_USER");
string DbPassword = Environment.GetEnvironmentVariable("DATABASE_PASSWORD");
string ConnectionString = $"Host=PostgreSQL;Port=5432;Database=sensors;Username={DbUser};Password={DbPassword}";
Collaborator

Why does file service connect to sensors DB?

Why does file service connect to sensors DB?
Collaborator

We don't get it to work . Fix issues and merge in next week branch

## We don't get it to work . Fix issues and merge in next week branch
a22erigr closed this pull request 2026-05-13 08:19:22 +00:00

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
5 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Andras/BoundlessFlowCampus2K!896
No description provided.