Skip to content

Native support for file uploads#559

Merged
Blacksmoke16 merged 18 commits intomasterfrom
file-uploads
Aug 2, 2025
Merged

Native support for file uploads#559
Blacksmoke16 merged 18 commits intomasterfrom
file-uploads

Conversation

@Blacksmoke16
Copy link
Copy Markdown
Member

@Blacksmoke16 Blacksmoke16 commented Jul 28, 2025

Context

Currently files uploaded within a multipart/form-data request have to be manually handled via HTTP::FormData.parse from the stdlib. This PR introduces a native way to easily handle file uploads much like you can handle serializing JSON request bodies.

Additionally, it also provides a new ATH::File concept that can be used to represent a file on the filesystem without having to actually open it via File.open.

NOTE: Usages of the stdlib File module MUST now be prefixed with ::.

Resolves #442

Changelog

  • Implement native file upload handling
    • Opt-in feature via new bundle schema configuration
    • Files are exposed via ATH::Request#files as an array of ATH::UploadedFile
    • New ATHA::MapUploadedFile provides a way similar to ATHA::MapRequestBody to access them more easily
    • Add support for ATH::UploadedFile to AVD::Constraints::File and AVD::Constraints::Image

Before merging, remember to add the athena-framework/athena prefix to the PR number in the PR title

@codecov
Copy link
Copy Markdown

codecov Bot commented Jul 31, 2025

Codecov Report

❌ Patch coverage is 98.25919% with 9 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...amework/spec/controllers/file_upload_controller.cr 83.33% 3 Missing ⚠️
src/components/framework/src/file_parser.cr 95.00% 2 Missing ⚠️
src/components/framework/spec/file_parser_spec.cr 97.82% 1 Missing ⚠️
src/components/framework/spec/file_spec.cr 98.73% 0 Missing and 1 partial ⚠️
...rc/components/framework/spec/uploaded_file_spec.cr 98.71% 1 Missing ⚠️
...dator/spec/constraints/file_validator_test_case.cr 94.44% 1 Missing ⚠️

❌ Your patch status has failed because the patch coverage (98.25%) is below the target coverage (100.00%). You can increase the patch coverage or adjust the target coverage.

Flag Coverage Δ
compiled 31.09% <9.28%> (-0.21%) ⬇️
unit 96.98% <98.01%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
clock 100.00% <ø> (ø)
console 97.20% <ø> (ø)
dependency_injection 93.16% <ø> (ø)
dotenv 98.38% <ø> (ø)
event_dispatcher 95.90% <ø> (ø)
framework 98.11% <98.28%> (+0.01%) ⬆️
image_size 96.63% <ø> (ø)
mercure 94.94% <ø> (ø)
mime 99.37% <ø> (ø)
negotiation 97.93% <ø> (ø)
routing 98.38% <ø> (ø)
serializer 95.83% <ø> (ø)
spec 93.80% <ø> (ø)
validator 95.90% <98.00%> (+0.01%) ⬆️

📢 Thoughts on this report? Let us know!

@Blacksmoke16 Blacksmoke16 marked this pull request as ready for review August 2, 2025 13:17
@Blacksmoke16 Blacksmoke16 merged commit 40d4312 into master Aug 2, 2025
12 of 14 checks passed
@Blacksmoke16 Blacksmoke16 deleted the file-uploads branch August 2, 2025 13:42
PallasAthenaie pushed a commit to athena-framework/contracts that referenced this pull request Aug 2, 2025
PallasAthenaie pushed a commit to athena-framework/framework that referenced this pull request Aug 2, 2025
PallasAthenaie pushed a commit to athena-framework/validator that referenced this pull request Aug 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

File Uploads

1 participant