You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: global upload manager to track file uploads outside of AttachmentManager (#1715)
## CLA
- [ ] I have signed the [Stream
CLA](https://docs.google.com/forms/d/e/1FAIpQLScFKsKkAJI7mhCr7K9rEIOpqIDThrWxuvxnwUq2XkHyG154vQ/viewform)
(required).
- [ ] Code changes are tested
## Description of the changes, What, Why and How?
RN PR for reference:
GetStream/stream-chat-react-native#3527
React Native allows hitting the send button before attachment uploads
are completed. This means they need a way to track attachment upload
status outside of `AttachmentManager`.
To solve this we have an `UploadManager` (can be accessed via
`client.uploadManager`) that uses the `AttachmentManager` of a given
channel to do attachment upload, and has a state to track
`uploadProgress` for attachments.
Attachments are tracked by `id` in `UploadManager`.
Long-term solution: we talked with @isekovanic that `messageComposer`
should have support for this feature, but that is a bigger task, not the
scope of this PR.
## Changelog
-
When using the message composer’s attachment manager, upload progress is tracked when `config.attachments.trackUploadProgress` is `true` (the default). Progress is stored on each attachment’s `localMetadata.uploadProgress` (0–100 for the default upload path, from the axios progress event; the initial state is 0% when the upload starts).
124
124
125
-
With a custom `doUploadRequest`, the function receives an optional second argument `options` with`onProgress?: (percent: number | undefined) => void`. Call `onProgress` from your upload implementation to drive the same `localMetadata.uploadProgress` updates. If you do not call it, `uploadProgress` stays at 0 until the upload finishes.
125
+
With a custom `doUploadRequest`, the function receives an optional second argument `options` with:
126
126
127
-
Set `trackUploadProgress` to `false` to skip setting `uploadProgress` (will be `undefined` in this case) and to omit progress callbacks to both the default channel upload and custom `doUploadRequest`.
127
+
-`onProgress?: (percent: number | undefined) => void` — call this from your upload implementation to drive the same `localMetadata.uploadProgress` updates. If you do not call it, `uploadProgress` stays at 0 until the upload finishes.
128
+
-`abortSignal?: AbortSignal` — the SDK aborts this signal when the upload is cancelled (for example the user removes the attachment, or `client.uploadManager.reset()` runs on disconnect). Forward it to your transport (axios `signal`, `fetch``signal`, etc.) if you want to cancel upload request.
129
+
130
+
Set `trackUploadProgress` to `false` to skip setting `uploadProgress` (will be `undefined` in this case) and to omit `onProgress` to both the default channel upload and custom `doUploadRequest`.
0 commit comments