Repository navigation
refactor: FileUploader.upload now uses StreamedRequest - #3695
Conversation
📝 Walkthrough""" WalkthroughThe changes update the minimum required version of the Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant FileUploader
participant HTTPServer
Client->>FileUploader: upload(stream, [length])
FileUploader->>FileUploader: Convert stream to ByteStream (if needed)
FileUploader->>HTTPServer: Send HTTP request with stream as body (no full buffering)
HTTPServer-->>FileUploader: HTTP response (status code)
FileUploader-->>Client: Return success/failure
Assessment against linked issues
Assessment against linked issues: Out-of-scope changesNo out-of-scope changes were found. All modifications are related to raising the minimum 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (55)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
01c3a43 to
dea9bab
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/serverpod_client/lib/src/file_uploader.dart (1)
75-78: Address the TODO: Add error logging.The TODO comment indicates missing error logging. Consider adding appropriate logging to help with debugging upload failures.
Would you like me to suggest a logging implementation that preserves the current return behavior while providing better debugging information?
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (21)
integrations/serverpod_cloud_storage_gcp/pubspec.yaml(1 hunks)integrations/serverpod_cloud_storage_s3/pubspec.yaml(1 hunks)modules/new_serverpod_auth/serverpod_auth_profile/serverpod_auth_profile_server/pubspec.yaml(1 hunks)modules/serverpod_auth/serverpod_auth_server/pubspec.yaml(1 hunks)modules/serverpod_chat/serverpod_chat_server/pubspec.yaml(1 hunks)packages/serverpod/pubspec.yaml(1 hunks)packages/serverpod_client/lib/src/file_uploader.dart(3 hunks)packages/serverpod_client/pubspec.yaml(1 hunks)templates/pubspecs/integrations/serverpod_cloud_storage_gcp/pubspec.yaml(1 hunks)templates/pubspecs/integrations/serverpod_cloud_storage_s3/pubspec.yaml(1 hunks)templates/pubspecs/modules/new_serverpod_auth/serverpod_auth_profile/serverpod_auth_profile_server/pubspec.yaml(1 hunks)templates/pubspecs/modules/serverpod_auth/serverpod_auth_server/pubspec.yaml(1 hunks)templates/pubspecs/modules/serverpod_chat/serverpod_chat_server/pubspec.yaml(1 hunks)templates/pubspecs/packages/serverpod/pubspec.yaml(1 hunks)templates/pubspecs/packages/serverpod_client/pubspec.yaml(1 hunks)templates/pubspecs/tests/bootstrap_project/pubspec.yaml(1 hunks)templates/pubspecs/tests/serverpod_test_server/pubspec.yaml(1 hunks)templates/pubspecs/tools/serverpod_cli/pubspec.yaml(1 hunks)tests/bootstrap_project/pubspec.yaml(1 hunks)tests/serverpod_test_server/pubspec.yaml(1 hunks)tools/serverpod_cli/pubspec.yaml(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (12)
- GitHub Check: Serverpod E2E web tests (3.24.0)
- GitHub Check: Serverpod E2E web tests (3.32.1)
- GitHub Check: Serverpod integration tests (server) (3.32.1)
- GitHub Check: Unit tests IO (3.32.1, windows-latest)
- GitHub Check: Unit tests IO (3.24.0, windows-latest)
- GitHub Check: Serverpod integration tests (server) (3.24.0)
- GitHub Check: serverpod generate (3.24.0)
- GitHub Check: serverpod generate (3.32.1)
- GitHub Check: Migration e2e tests (3.32.1)
- GitHub Check: Migration e2e tests (3.24.0)
- GitHub Check: dart analyze downgrade (3.32.1, windows-latest)
- GitHub Check: dart analyze downgrade (3.24.0, windows-latest)
🔇 Additional comments (26)
packages/serverpod_client/lib/src/file_uploader.dart (6)
3-3: LGTM: Required import for async utilities.The
dart:asyncimport is correctly added to support theunawaitedfunction used in the streaming implementation.
24-28: LGTM: Efficient ByteStream creation and delegation.The refactored
uploadByteDatamethod efficiently creates aByteStreamfrom the buffer and delegates to the unified_uploadmethod. This maintains the same interface while leveraging the new streaming architecture.
31-32: LGTM: Enhanced method signature with optional length parameter.The addition of the optional
lengthparameter is a good enhancement that enables more efficient streaming when the content length is known upfront. The use of the extension method to convert toByteStreamis clean.
34-54: LGTM: Proper streaming implementation for binary uploads.The binary upload implementation correctly uses
StreamedRequestand pipes the stream directly to the request sink usingunawaited. This achieves the goal of reducing memory pressure by avoiding buffering the entire content in memory.
65-74: LGTM: Clean multipart request handling.The multipart request construction and field handling is implemented correctly. The response status code check (204) is appropriate for multipart uploads.
117-123: LGTM: Efficient stream conversion extension.The extension method correctly checks if the stream is already a
ByteStreamto avoid unnecessary conversion, which is a good optimization. The implementation is clean and follows Dart conventions.modules/serverpod_auth/serverpod_auth_server/pubspec.yaml (1)
22-22: Consistent HTTP version bump to support StreamedRequest
Updated thehttpdependency to>=1.1.0 <2.0.0, aligning with the newly introduced StreamedRequest usage in FileUploader.templates/pubspecs/tools/serverpod_cli/pubspec.yaml (1)
17-17: Align HTTP constraint with core packages
Raised the lower bound forhttpto>=1.1.0 <2.0.0to ensure availability of streaming APIs. This matches the other pubspec templates.integrations/serverpod_cloud_storage_gcp/pubspec.yaml (1)
18-18: Update HTTP dependency for stream support
Bumpedhttpto>=1.1.0 <2.0.0, consistent with the rest of the repository and required for streamed uploads.packages/serverpod_client/pubspec.yaml (1)
16-16: Sync HTTP version with client requirements
Lower bound ofhttpupdated to>=1.1.0 <2.0.0so that FileUploader can utilize StreamedRequest without version conflicts.tools/serverpod_cli/pubspec.yaml (1)
18-18: Maintain uniform HTTP version across CLI tools
Adjustedhttpconstraint to>=1.1.0 <2.0.0in the CLI pubspec, matching templates and modules for streaming support.packages/serverpod/pubspec.yaml (1)
26-26: ```shell
#!/bin/bashList all pubspec.yaml files with any http dependency line
rg -n "http:" --glob '**/pubspec.yaml'
Specifically search for the old constraint pattern
rg -n "http:.*>=1.0.0 <2.0.0" --glob '**/pubspec.yaml'
</details> <details> <summary>templates/pubspecs/modules/serverpod_chat/serverpod_chat_server/pubspec.yaml (1)</summary> `15-15`: **Bump HTTP dependency version in chat server template** Aligned HTTP lower bound to `>=1.1.0` in the chat server template to match updated streaming requirements. </details> <details> <summary>templates/pubspecs/packages/serverpod_client/pubspec.yaml (1)</summary> `15-15`: **Bump HTTP dependency version in client template** Updated HTTP lower bound to `>=1.1.0` in the client template for consistency with streaming support. </details> <details> <summary>modules/serverpod_chat/serverpod_chat_server/pubspec.yaml (1)</summary> `16-16`: **Bump HTTP dependency version in chat module** Aligned HTTP lower bound to `>=1.1.0` for the chat module’s pubspec to ensure compatibility with streamed uploads. </details> <details> <summary>templates/pubspecs/integrations/serverpod_cloud_storage_gcp/pubspec.yaml (1)</summary> `17-17`: **Bump HTTP dependency version in GCP integration template** Raised HTTP lower bound to `>=1.1.0` in the GCP integration template to support streamed requests. </details> <details> <summary>integrations/serverpod_cloud_storage_s3/pubspec.yaml (1)</summary> `17-17`: **Raise HTTP dependency lower bound to 1.1.0** Ensures availability of `StreamedRequest` introduced in `http` v1.1.0 for streaming uploads. Upper bound remains `<2.0.0` for compatibility. </details> <details> <summary>templates/pubspecs/modules/serverpod_auth/serverpod_auth_server/pubspec.yaml (1)</summary> `21-21`: **Update HTTP package constraint to support streaming** Aligns with the refactor requiring `StreamedRequest` in `http` v1.1.0+. Maintains `<2.0.0` to avoid breaking changes. </details> <details> <summary>tests/bootstrap_project/pubspec.yaml (1)</summary> `11-11`: **Bump HTTP minimum version to 1.1.0 for streaming support** Consistent with other projects—ensures new upload logic works with `http` v1.1.0+. </details> <details> <summary>tests/serverpod_test_server/pubspec.yaml (1)</summary> `14-14`: **Require HTTP ≥1.1.0 to enable StreamedRequest** Matches the updated client logic and maintains backward compatibility under `<2.0.0`. </details> <details> <summary>templates/pubspecs/tests/bootstrap_project/pubspec.yaml (1)</summary> `11-11`: **Increase HTTP lower bound to 1.1.0** Guarantees the presence of streaming APIs in `http` v1.1.0+. Upper bound cap remains appropriate. </details> <details> <summary>templates/pubspecs/packages/serverpod/pubspec.yaml (1)</summary> `25-25`: ```shell #!/bin/bash # List every http dependency line across all pubspec.yaml files for manual inspection find . -type f -name "pubspec.yaml" -print0 | xargs -0 rg -Hn "^\s*http:"modules/new_serverpod_auth/serverpod_auth_profile/serverpod_auth_profile_server/pubspec.yaml (1)
13-13: Bumped http dependency in generated auth profile server
Lower bound updated to>=1.1.0 <2.0.0, aligning with the core template change. Since this is a generated file, confirm that the corresponding template was updated so regeneration retains this constraint.templates/pubspecs/integrations/serverpod_cloud_storage_s3/pubspec.yaml (1)
16-16: Aligned http version constraint in S3 integration template
Lower bound bumped to>=1.1.0 <2.0.0, consistent with other templates. The syntax is correct and should satisfy the updated upload implementation requirements.templates/pubspecs/modules/new_serverpod_auth/serverpod_auth_profile/serverpod_auth_profile_server/pubspec.yaml (1)
12-12: Updated http dependency in auth profile template
Constraint correctly raised to>=1.1.0 <2.0.0, matching the required baseline for StreamedRequest usage.templates/pubspecs/tests/serverpod_test_server/pubspec.yaml (1)
13-13: Raised http dependency floor in test server template
Lower bound updated to>=1.1.0 <2.0.0, aligning test environments with production dependencies.
dea9bab to
84b7960
Compare
tp
left a comment
There was a problem hiding this comment.
The ByteData to Stream conversion looks fishy, otherwise the implementation looks fine to me.
Still have some questions though, and without more tests I would probably not ship this right now. But unless I missed more test, smothering this with E2E ones seems longer overdue anyway, and would thus be greatly appreciated I suppose.
(Also should think whether we should be using this FileUploader pattern for the profile image, instead of sending bytes through the Serverpod API and then forwarding that to the bucket store.)
|
As I said before I logged #3633 and used this PR to test my implementation. This PR fixes
The upload of my 74mb apk went through without any issues. 🚀 🎉 |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
tests/serverpod_test_server/test_e2e/cloud_storage_test.dart (1)
14-25: Fix typo in parameter name.The extension method logic is correct and efficiently chunks stream elements into fixed-size lists. However, there's a typo in the parameter name.
- Stream<List<T>> inChunks(int chunckSize) async* { + Stream<List<T>> inChunks(int chunkSize) async* { var chunk = <T>[]; await for (final e in this) { chunk.add(e); - if (chunk.length >= chunckSize) { + if (chunk.length >= chunkSize) { yield chunk; chunk = <T>[]; // new }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
packages/serverpod_client/lib/src/file_uploader.dart(3 hunks)tests/serverpod_test_server/test_e2e/cloud_storage_test.dart(3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/serverpod_client/lib/src/file_uploader.dart
⏰ Context from checks skipped due to timeout of 90000ms (56)
- GitHub Check: Serverpod integration tests (flutter)
- GitHub Check: Bootstrap tests (3.24.0, ubuntu-latest, tests/bootstrap_project)
- GitHub Check: CLI e2e tests (3.32.1, ubuntu-latest, tests/serverpod_cli_e2e_test)
- GitHub Check: CLI e2e tests (3.24.0, ubuntu-latest, tests/serverpod_cli_e2e_test)
- GitHub Check: Bootstrap tests (3.32.1, ubuntu-latest, tests/bootstrap_project)
- GitHub Check: Bootstrap tests (3.32.1, windows-latest, tests/bootstrap_project)
- GitHub Check: Bootstrap tests (3.24.0, windows-latest, tests/bootstrap_project)
- GitHub Check: Migration e2e tests (3.24.0)
- GitHub Check: Serverpod concurrent integration tests (server) (3.24.0)
- GitHub Check: Migration e2e tests (3.32.1)
- GitHub Check: Version change test
- GitHub Check: Serverpod concurrent integration tests (server) (3.32.1)
- GitHub Check: Module integration tests in tests/serverpod_test_nonvector/serverpod_test_nonvector_server with Flutter 3.32.1
- GitHub Check: Module integration tests in modules/new_serverpod_auth/serverpod_auth_jwt/serverpod_auth_jwt_server with Flutter 3.24.0
- GitHub Check: Module integration tests in modules/new_serverpod_auth/serverpod_auth_profile/serverpod_auth_profile_server with Flutter 3.32.1
- GitHub Check: Module integration tests in modules/serverpod_auth/serverpod_auth_server with Flutter 3.32.1
- GitHub Check: Module integration tests in tests/serverpod_test_module/serverpod_test_module_server with Flutter 3.32.1
- GitHub Check: Module integration tests in modules/new_serverpod_auth/serverpod_auth_profile/serverpod_auth_profile_server with Flutter 3.24.0
- GitHub Check: Module integration tests in modules/new_serverpod_auth/serverpod_auth_email_account/serverpod_auth_email_account_server with Flutter 3.32.1
- GitHub Check: Module integration tests in modules/new_serverpod_auth/serverpod_auth_session/serverpod_auth_session_server with Flutter 3.32.1
- GitHub Check: Module integration tests in modules/new_serverpod_auth/serverpod_auth_jwt/serverpod_auth_jwt_server with Flutter 3.32.1
- GitHub Check: Module integration tests in tests/serverpod_new_auth_test/serverpod_new_auth_test_server with Flutter 3.24.0
- GitHub Check: Module integration tests in tests/serverpod_new_auth_test/serverpod_new_auth_test_server with Flutter 3.32.1
- GitHub Check: Module integration tests in modules/serverpod_auth/serverpod_auth_server with Flutter 3.24.0
- GitHub Check: Module integration tests in modules/new_serverpod_auth/serverpod_auth_session/serverpod_auth_session_server with Flutter 3.24.0
- GitHub Check: Module integration tests in modules/new_serverpod_auth/serverpod_auth_email_account/serverpod_auth_email_account_server with Flutter 3.24.0
- GitHub Check: Module integration tests in tests/serverpod_test_nonvector/serverpod_test_nonvector_server with Flutter 3.24.0
- GitHub Check: Unit tests Web (3.32.1, ubuntu-latest)
- GitHub Check: Unit tests Web (3.24.0, ubuntu-latest)
- GitHub Check: Unit tests Web (3.24.0, windows-latest)
- GitHub Check: Unit tests IO (3.32.1, ubuntu-latest)
- GitHub Check: Unit tests Web (3.32.1, windows-latest)
- GitHub Check: Unit tests IO (3.24.0, windows-latest)
- GitHub Check: Unit tests IO (3.32.1, windows-latest)
- GitHub Check: Unit tests IO (3.24.0, ubuntu-latest)
- GitHub Check: dart analyze downgrade (3.24.0, ubuntu-latest)
- GitHub Check: dart analyze downgrade (3.32.1, ubuntu-latest)
- GitHub Check: dart analyze downgrade (3.32.1, windows-latest)
- GitHub Check: dart analyze downgrade (3.24.0, windows-latest)
- GitHub Check: update pubspecs (3.32.1)
- GitHub Check: Flutter unit tests (3.32.1, windows-latest, packages/serverpod_flutter)
- GitHub Check: Serverpod integration tests (server) (3.24.0)
- GitHub Check: Flutter unit tests (3.24.0, windows-latest, packages/serverpod_flutter)
- GitHub Check: Flutter unit tests (3.32.1, ubuntu-latest, packages/serverpod_flutter)
- GitHub Check: Serverpod integration tests (server) (3.32.1)
- GitHub Check: Serverpod E2E web tests (3.32.1)
- GitHub Check: Serverpod E2E web tests (3.24.0)
- GitHub Check: serverpod generate (3.32.1)
- GitHub Check: serverpod generate (3.24.0)
- GitHub Check: dart analyze latest (3.32.1, ubuntu-latest)
- GitHub Check: dart analyze latest (3.32.1, windows-latest)
- GitHub Check: dart analyze (3.24.0, windows-latest)
- GitHub Check: Serverpod E2E IO tests (3.32.1)
- GitHub Check: Serverpod E2E IO tests (3.24.0)
- GitHub Check: dart analyze (3.24.0, ubuntu-latest)
- GitHub Check: Serverpod integration tests (3.32.1, packages/serverpod_shared)
🔇 Additional comments (6)
tests/serverpod_test_server/test_e2e/cloud_storage_test.dart (6)
2-2: LGTM: Import added for async stream functionality.The
dart:asyncimport is correctly added to support the new stream-based testing functionality.
9-12: LGTM: Infinite byte stream generator implementation is correct.The
streamBytes()function correctly generates an infinite stream of bytes cycling from 0 to 255, which is perfect for testing streaming uploads with predictable data patterns.
160-160: LGTM: Test name clarification improves readability.Renaming the test to explicitly mention "ByteData" improves clarity and distinguishes it from the new streaming test.
176-181: LGTM: Consistent test naming with the upload test.The test name change maintains consistency with the corresponding upload test and improves test organization.
183-201: Excellent streaming upload test coverage.This test comprehensively validates the new streaming upload functionality by:
- Creating a 512-byte stream in 64-byte chunks
- Verifying successful upload
- Confirming file verification
- Validating retrieved file content and size
The test effectively demonstrates the streaming capability that addresses the PR objective of reducing memory pressure during uploads.
203-221: LGTM: Important state management validation.This test correctly validates that FileUploader instances can only be used once, which is crucial for preventing unintended reuse. The exception message verification ensures proper error handling and user feedback.
9d52a69 to
eb181eb
Compare
…n't impact tests)
tp
left a comment
There was a problem hiding this comment.
LGTM 🚀
Just a tiny nit on the test helper, but hey, it's only used internally and easily read through :)
(And seems fine to leave the old tests as is for now, as Alex said this will get an overhaul later this year.)
Strive to reduce memory pressure during upload by supporting streamed upload via
StreamedRequest.Updates
httppackage dependency and refactorsFileUploaderfor improved stream handling.Closes: #3692
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
Summary by CodeRabbit
Refactor
Chores
httppackage to 1.1.0 across all packages, modules, templates, and tests to ensure compatibility with newer features and fixes.Tests