Repository navigation
feat: Cloud storage improvements - #4771
Merged
Merged
Conversation
nielsenko
marked this pull request as draft
February 25, 2026 10:30
nielsenko
force-pushed
the
feat-cloud-storage-revamp
branch
3 times, most recently
from
February 25, 2026 11:35
bcae0ed to
d4d2830
Compare
Introduce serverpod_cloud_storage_s3_compat with: - S3EndpointConfig abstraction with AWS, GCP, and custom implementations - S3UploadStrategy interface with multipart POST strategy - S3Client for SigV4-signed API requests (GET, HEAD, DELETE) - S3CompatCloudStorage base class wiring everything together Upload strategies use Future<void> and throw typed exceptions (S3Exception, NoPermissionsException) on failure. Includes design documentation and comprehensive unit tests.
Refactor serverpod_cloud_storage_s3 and serverpod_cloud_storage_gcp to thin wrappers around S3CompatCloudStorage, eliminating duplicated S3 signing and upload logic.
Implements NativeGoogleCloudStorage that uses Google's native JSON API with service account credentials for signing, rather than HMAC/S3-compat. Includes unit tests for the native GCS implementation.
New serverpod_cloud_storage_r2 package using presigned PUT upload strategy. Includes s3_compat dependency override for test servers. Uses the mime package for content type detection in presigned PUT URLs. Also adds R2 endpoint config and binary upload support to FileUploader.
Add createDirectFileUploadDescription to NativeGoogleCloudStorage using signed URL v4 for direct browser-to-GCS uploads, with ACL header support.
- Add LICENSE, CHANGELOG, README to new packages. - Add pubspec templates and update_pubspecs script. - Add integration tests for S3-compat, native GCS, and R2 providers with shared test helper. - Add CI workflow andrun_tests_integration_cloud script. - Fix Given-When-Then test patterns.
…orageAccess Add optional maxFileSize, expirationDuration, and contentLength parameters to StorageAccess.createDirectFileUploadDescription, forwarding them to the underlying CloudStorage implementations. When contentLength is provided: - Validated against maxFileSize (throws if exceeded) - Signed into presigned PUT URLs for R2 and NativeGCS, enabling server-side enforcement of exact file size - For S3/GCP HMAC (multipart POST), content-length-range policy already enforces maxFileSize When contentLength is omitted, behavior is unchanged (backwards compatible). Closes: #4733
Add Application Default Credentials (ADC) support via: - IAM signBlob API for remote signing - GCE metadata server for service account email discovery Replace Completer-based initialization with async factory constructors: - create(): loads credentials from Serverpod password system - fromServiceAccountJson(): authenticates with explicit JSON - fromApplicationDefaultCredentials(): uses ADC - withStorageApi / withSigningCredentials / withAuthClient: sync (test-only)
Add optional named preventOverwrite parameter to both storeFile and createDirectFileUploadDescription. If set to `true` it prevents uploading to a path where an object already exists, if supported by the specific provider. - GCS native: ifGenerationMatch: '0' (storeFile) / x-goog-if-generation-match: 0 (direct upload) - S3 presigned PUT (AWS, R2): If-None-Match: * header - S3 multipart POST: not supported (flag is accepted but ignored)
…ativeGoogleCloudStorage - Replace _detectMimeType with lookupMimeType from the mime package. - Add close() for HTTP client cleanup. - Replace manual byte concatenation with BytesBuilder. - Fix query parameter sorting in signed URL generation. - Fix integration test to use async fromServiceAccountJson factory.
- Fix silent error swallowing: retrieveFile, fileExists, and deleteFile now properly distinguish 404 from server errors (5xx) instead of treating all non-200 responses as 'not found' - Add public check to getPublicUrl to skip HEAD request for non-public storage (matching NativeGoogleCloudStorage behavior) - Fix HTTP client leak in PresignedPutUploadStrategy.uploadData by properly creating and closing an http.Client instead of using the global http.put() function - Add close() to S3Client and S3CompatCloudStorage for resource cleanup - Fix ByteData buffer aliasing in retrieveFile by using ByteData.sublistView - Fix Policy expiration to use proper ISO 8601 formatting instead of relying on DateTime.toString() which produces microsecond precision - Rename misnamed cloud_storage.dart directory to cloud_storage in S3 package and replace placeholder library docs - Improve GCP HMAC credential error messages to include env var hints - Document MultipartPostUploadStrategy preventOverwrite limitation
nielsenko
force-pushed
the
feat-cloud-storage-revamp
branch
from
February 25, 2026 11:44
d4d2830 to
0ad3287
Compare
Collaborator
Author
|
Rebased on main |
nielsenko
marked this pull request as ready for review
February 25, 2026 12:09
nielsenko
force-pushed
the
feat-cloud-storage-revamp
branch
10 times, most recently
from
February 26, 2026 10:11
2550be1 to
05c9998
Compare
nielsenko
force-pushed
the
feat-cloud-storage-revamp
branch
from
February 26, 2026 10:14
05c9998 to
1d438f5
Compare
nielsenko
marked this pull request as draft
February 26, 2026 10:15
…tegration_test_support package The Dart package validator rejects importing `test` from `lib/` when it is only a dev dependency, but promoting it to a regular dependency would leak it to all consumers of `serverpod_cloud_storage_s3_compat`. - Create a local-only (`publish_to: none`) package that owns the `test` dependency and hosts `runS3CompatIntegrationTests` and `S3CompatTestConfig` - Move the shared test suite out of `serverpod_cloud_storage_s3_compat/lib/` - Update consumer packages (S3, R2, GCP) to import from the new package - Update INTEGRATION_TESTING.md to reflect the new structure
Replaces the single matrix job with four independent jobs (AWS S3, Cloudflare R2, GCP, GCP Native), each with only the secrets it needs. Skips at job level when credentials are missing. Switches from Flutter to dart-lang/setup-dart and removes the multi-version matrix.
…oad strategies Add supportsPreventOverwrite flag to skip preventOverwrite integration tests when using MultipartPostUploadStrategy (which cannot support it). Run the shared test suite twice for AWS S3 and GCP S3-compat: once with MultipartPost and once with PresignedPut (which supports preventOverwrite). Also fix secret names in CI workflow (remove incorrect SERVERPOD_ prefix).
nielsenko
force-pushed
the
feat-cloud-storage-revamp
branch
from
February 26, 2026 11:05
1d438f5 to
bf9a949
Compare
Add supportsObjectAcl capability to S3EndpointConfig (defaults true). GCP and R2 override to false. MultipartPostUploadStrategy and Policy conditionally omit ACL fields/conditions based on this flag. Also switch endpoint configs from implements to extends, and disable preventOverwrite tests for GCP S3-compat (no If-None-Match support).
nielsenko
force-pushed
the
feat-cloud-storage-revamp
branch
from
February 26, 2026 12:45
39c5417 to
e7594b8
Compare
…eAccess StorageAccess.storeFile and createDirectFileUploadDescription now accept contentLength and preventOverwrite as direct named parameters instead of exposing the CloudStorageOptions type. The options object is built internally before dispatching to the mixin.
nielsenko
marked this pull request as ready for review
February 26, 2026 15:05
marcelomendoncasoares
requested changes
Feb 27, 2026
marcelomendoncasoares
left a comment
Collaborator
There was a problem hiding this comment.
Great work with this big refactor! Only a few suggestions and questions on the comments.
nielsenko
force-pushed
the
feat-cloud-storage-revamp
branch
from
February 27, 2026 09:07
5924855 to
1f5bf6d
Compare
Move AwsEndpointConfig, GcpEndpointConfig, and R2EndpointConfig from the base s3_compat package to their respective provider packages (serverpod_cloud_storage_s3, _gcp, _r2). The base package retains only the abstract S3EndpointConfig and the generic CustomEndpointConfig. Update s3_compat tests to use CustomEndpointConfig as a generic fixture instead of depending on provider-specific implementations.
nielsenko
force-pushed
the
feat-cloud-storage-revamp
branch
from
February 27, 2026 10:04
32cfe04 to
21e64b2
Compare
marcelomendoncasoares
requested changes
Feb 27, 2026
marcelomendoncasoares
left a comment
Collaborator
There was a problem hiding this comment.
Just a few more comments on the tests and one point for discussion regarding the folder name for the endpoint config classes.
nielsenko
force-pushed
the
feat-cloud-storage-revamp
branch
from
February 27, 2026 16:33
3730daa to
c432352
Compare
Rename src/endpoints/ to src/config/ in all cloud storage packages to avoid confusion with Serverpod Endpoint classes. Also address remaining review comments: - Break special-character path tests into separate Given scenarios - Extract 1MB upload test into its own Given group - Remove redundant inline comments in delete tests - Remove inaccurate comment about throwing behavior - Add unit tests for DatabaseCloudStorage preventOverwrite and contentLength validation
nielsenko
force-pushed
the
feat-cloud-storage-revamp
branch
from
February 27, 2026 16:36
c432352 to
767df43
Compare
marcelomendoncasoares
approved these changes
Feb 27, 2026
marcelomendoncasoares
left a comment
Collaborator
There was a problem hiding this comment.
Only one minor suggestion to replicate the changes done on the run_s3_compat_integration_tests.dart to the other similar storage tests (like the native_gcp_integration_test.dart). Apart from this, LGTM! 🚀
I'll leave it already approved, so feel free to merge directly after synchronizing the tests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refactor cloud storage with shared S3-compatible base package
Introduces a layered architecture for cloud storage integrations, eliminating code duplication between S3 and GCP packages while adding support for new providers.
Shared base package (
serverpod_cloud_storage_s3_compat)S3CompatCloudStoragebase implementation using configurable abstractionsS3EndpointConfiginterface with implementations for AWS, GCP, R2, and custom endpointsS3UploadStrategyinterface with multipart POST (AWS/GCP/MinIO) and presigned PUT (R2) strategiesS3Clientfor signed S3 API requests with proper resource lifecycle (close())Native Google Cloud Storage (
NativeGoogleCloudStorage)signBlobAPI and GCE metadata serverpointycastle(avoidsgoogleapis_auth^2.1.0 dependency chain that forces Flutter 3.38.1+)create(),fromServiceAccountJson(),fromApplicationDefaultCredentials()New features
preventOverwriteparameter onstoreFileandcreateDirectFileUploadDescription— prevents uploading to an existing path (GCS native:ifGenerationMatch: '0'; S3 presigned PUT:If-None-Match: *; S3 multipart POST: not supported)maxFileSize,expirationDuration, andcontentLengthexposed onStorageAccess.createDirectFileUploadDescription. WhencontentLengthis provided it is validated againstmaxFileSizeand signed into presigned PUT URLs, enabling server-side enforcement of exact file sizeserverpod_cloud_storage_r2package for Cloudflare R2 supportFileUploaderupdated to support PUT method and custom headers for R2-style uploadsHardening & cleanup
retrieveFile,fileExists, anddeleteFilenow properly distinguish 404 from 5xx errorsPresignedPutUploadStrategy.uploadDataByteDatabuffer aliasing inretrieveFileusingByteData.sublistViewPolicyexpiration to use proper ISO 8601 formattingclose()toS3ClientandS3CompatCloudStoragefor resource cleanupmimepackageCompleterpattern with async factory constructors (eliminates race betweenisCompletedchecks and async init)Fixes #4623
Fixes #4588
Fixes #4733
Fixes #1625
Closes: #3701
Related:
Pre-launch Checklist
///), and made sure that the documentation follows the same style as other Serverpod documentation. I checked spelling and grammar.If you need help, consider asking for advice on the discussion board.
Breaking changes
None. Refactored packages maintain full backwards compatibility with same constructor parameters and environment variable names.