Skip to content

refactor: Update CloudStorage interface - #5621

Merged
Crazelu merged 43 commits into
serverpod:mainfrom
Crazelu:refactor/cloud-storage
Aug 26, 2026
Merged

Crazelu merged 43 commits into
serverpod:mainfrom
Crazelu:refactor/cloud-storage

Conversation

@Crazelu

@Crazelu Crazelu commented Aug 20, 2026 •

Copy link
Copy Markdown
Collaborator

The CloudStorage interface now supports metadata and temporary URLs. Upload description is now typed. Methods that previously had nullable return types now opt for throwing exceptions instead of returning null.

This refactor comes with hardened validation of provided options with exceptions thrown instead of silently ignoring.

Closes #4848

Pre-launch Checklist

  • I read the Contribute page and followed the process outlined there for submitting PRs.
  • This update contains only one single feature or bug fix and nothing else. (If you are submitting multiple fixes, please make multiple PRs.)
  • I read and followed the Dart Style Guide and formatted the code with dart format.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///), and made sure that the documentation follows the same style as other Serverpod documentation. I checked spelling and grammar.
  • I added new tests to check the change I am making.
  • All existing and new tests are passing.
  • Any breaking changes are documented below.

If you need help, consider asking for advice on the discussion board.

Breaking changes

  • Several CloudStorage methods have been replaced or changed shape.
  • CloudStorage methods now throw exceptions instead of doing nothing or returning null.
  • Options like preventOverwrite are no longer silently ignored by implementations that don't support them; an exception is thrown instead.
  • Upload description is now typed.

@Crazelu
Crazelu requested review from a team, Isakdl and nielsenko August 20, 2026 13:05

@nielsenko nielsenko left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should take the opportunity to change more. Here are my suggestions (with the help of claude for the table). So File on all file related methods, direction on Uri related ones (Download/Upload), drop Direct, etc.

CloudStorage

Before After Change
storeFile(byteData, expiration, verified) -> void storeFile(byteData, options) -> void expiration -> options; verified removed
storeFileWithOptions(byteData, expiration, verified, options) (deleted) merged into storeFile
retrieveFile() -> ByteData? retrieveFile() -> ByteData? unchanged
(none) statFile() -> FileStat? new
fileExists() -> bool fileExists() -> bool now a default method over statFile
deleteFile() -> void deleteFile() -> void unchanged
getPublicUrl() -> Uri? publicDownloadUrl() -> Uri? renamed
(none) temporaryDownloadUrl(options) -> Uri? new
createDirectFileUploadDescription(expirationDuration, maxFileSize) -> String? createUploadDescription(options) -> String? renamed; both params -> options
createDirectFileUploadDescriptionWithOptions(..., options) (deleted) merged into createUploadDescription
verifyDirectFileUpload() -> bool verifyUpload() -> bool renamed

StorageAccess

Before After Change
storeFile(byteData, expiration, preventOverwrite) storeFile(byteData, options) flattened params -> StoreFileOptions
createDirectFileUploadDescription(expirationDuration, maxFileSize, contentLength, preventOverwrite) createUploadDescription(options) 4 params -> UploadOptions
getPublicUrls(paths) -> List<Uri?> publicDownloadUrls(paths) renamed
(none) temporaryDownloadUrl(options), statFile() new pass-throughs
null-check repeated 8x _storage(storageId) helper dedup
(none) contentLength <= maxFileSize check hoisted from 3 impls

Types

Type Fields Used by
StoreFileOptions expiration, preventOverwrite, metadata storeFile
UploadOptions expirationDuration, maxFileSize, contentLength, preventOverwrite, metadata createUploadDescription
TemporaryDownloadUrlOptions expirationDuration, downloadFileName, contentType temporaryDownloadUrl
FileMetadata contentType, cacheControl, contentDisposition, contentEncoding, custom write-time; in both upload options types
FileStat size, lastModified, contentType, etag, custom read-time; statFile()
CloudStorageOptions (removed) split into the 3 above
CloudStorageWithOptions (removed) deleted

Behaviour

Area Before After
Unsupported option silently dropped must throw CloudStorageException
preventOverwrite on DB direct upload accepted, ignored throws (or ON CONFLICT DO NOTHING + migration)
verified: false on public interface, ignored by S3 and GCP DatabaseCloudStorage.storeUnverifiedFile
Content type, DB reads guessed from 12-entry map stored value; extension guess as fallback
fileExists on S3 HEAD, discards headers HEAD via statFile, headers kept
expiration on DB entries written, never enforced enforced (prerequisite for download tokens)

@Crazelu
Crazelu force-pushed the refactor/cloud-storage branch from 2b435f4 to 9168b91 Compare August 24, 2026 17:44
@Crazelu
Crazelu marked this pull request as ready for review August 24, 2026 19:38
@Crazelu
Crazelu requested review from a team and nielsenko August 24, 2026 19:38

@nielsenko nielsenko left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly questions

@nielsenko nielsenko left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Crazelu
Crazelu merged commit 888ed56 into serverpod:main Aug 26, 2026
480 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 26, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Discussion: extending CloudStorage vs provider-specific APIs for advanced storage capabilities

3 participants