Skip to content

feat: add attachment manager middleware for pre-upload and post-upload events#1588

Merged
MartinCupela merged 4 commits intomasterfrom
feat/attachment-manager-middleware
Aug 1, 2025
Merged

feat: add attachment manager middleware for pre-upload and post-upload events#1588
MartinCupela merged 4 commits intomasterfrom
feat/attachment-manager-middleware

Conversation

@MartinCupela
Copy link
Contributor

Goal

Allow integrators to customize the pre-upload and post-upload logic for attachments.

chatClient.setMessageComposerSetupFunction(({ composer }) => {
      ...
      composer.attachmentManager.preUploadMiddlewareExecutor.insert({
        middleware: [createCustomPreUploadMiddleware(composer)],
        position: {
          after: 'stream-io/attachment-manager-middleware/blocked-upload-notification',
        },
        unique: true,
      });

      composer.attachmentManager.postUploadMiddlewareExecutor.insert({
        middleware: [createCustomPostUploadMiddleware(composer)],
        position: {
          before: 'stream-io/attachment-manager-middleware/post-upload-enrichment',
        },
        unique: true,
      });
    });

Middleware handlers of the same eventName can now be executed concurrently. This is necessary to perform all the attachment uploads.

Details

  • The upload config check has been moved to pre-upload middleware and thus can be replaced with custom upload config check for a CDN other than Stream's
  • It is not necessary to provide a filter function (fileUploadFilter) as the filtering can take place inside the middleware
  • The post upload middleware executor allows for handling upload errors, further attachment enrichment, notifications etc.

Deprecations

  • AttachmentManager.fileUploadFilter() getter and setter - replaced with middleware handlers
  • AttachmentManager.fileToLocalUploadAttachment(file) - replaced with static AttachmentManager.toLocalUploadAttachment(file)
  • AttachmentManager.uploadAttachment(attachment) - replaced with AttachmentManager.uploadFile(file)

@github-actions
Copy link
Contributor

Size Change: +3.59 kB (+0.81%)

Total Size: 445 kB

Filename Size Change
dist/cjs/index.browser.cjs 129 kB +1.18 kB (+0.92%)
dist/cjs/index.node.cjs 174 kB +1.18 kB (+0.68%)
dist/esm/index.js 142 kB +1.23 kB (+0.87%)

compressed-size-action

@MartinCupela MartinCupela merged commit a8b0497 into master Aug 1, 2025
4 checks passed
@MartinCupela MartinCupela deleted the feat/attachment-manager-middleware branch August 1, 2025 15:35
github-actions bot pushed a commit that referenced this pull request Aug 1, 2025
## [9.14.0](v9.13.0...v9.14.0) (2025-08-01)

### Bug Fixes

* consider locally filtered messages in message pagination params calculation ([#1595](#1595)) ([b2c01e8](b2c01e8))
* keep pinned message data upon message editing ([#1590](#1590)) ([3bcfc28](3bcfc28))

### Features

* add attachment manager middleware for pre-upload and post-upload events ([#1588](#1588)) ([a8b0497](a8b0497))

### Chores

* **deps:** upgrade form-data to version 4.0.4 ([#1592](#1592)) ([2dd6676](2dd6676))
@stream-ci-bot
Copy link

🎉 This PR is included in version 9.14.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants