Skip to content

Conversation

@mifi
Copy link
Contributor

@mifi mifi commented Sep 19, 2025

closes #5921

also improve tests that currently depend on eachother

todo

@changeset-bot
Copy link

changeset-bot bot commented Sep 19, 2025

🦋 Changeset detected

Latest commit: 2cd02ac

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@uppy/companion Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Sep 19, 2025

Diff output files
diff --git a/packages/@uppy/companion/lib/server/Uploader.d.ts b/packages/@uppy/companion/lib/server/Uploader.d.ts
index 8c222eb..825d14f 100644
--- a/packages/@uppy/companion/lib/server/Uploader.d.ts
+++ b/packages/@uppy/companion/lib/server/Uploader.d.ts
@@ -52,9 +52,9 @@ declare class Uploader {
      * @property {number} [chunkSize]
      * @property {string} [providerName]
      *
-     * @param {UploaderOptions} options
+     * @param {UploaderOptions} optionsIn
      */
-    constructor(options: {
+    constructor(optionsIn: {
         endpoint: string;
         uploadUrl?: string;
         protocol: string;
@@ -75,6 +75,7 @@ declare class Uploader {
     storage: import("ioredis").Redis;
     providerName: string;
     options: {
+        headers: any;
         endpoint: string;
         uploadUrl?: string;
         protocol: string;
@@ -85,7 +86,6 @@ declare class Uploader {
         metadata: any;
         companionOptions: any;
         storage?: any;
-        headers?: any;
         httpMethod?: string;
         useFormData?: boolean;
         chunkSize?: number;
diff --git a/packages/@uppy/companion/lib/server/Uploader.js b/packages/@uppy/companion/lib/server/Uploader.js
index 310c2ba..966a17c 100644
--- a/packages/@uppy/companion/lib/server/Uploader.js
+++ b/packages/@uppy/companion/lib/server/Uploader.js
@@ -122,10 +122,17 @@ export default class Uploader {
    * @property {number} [chunkSize]
    * @property {string} [providerName]
    *
-   * @param {UploaderOptions} options
+   * @param {UploaderOptions} optionsIn
    */
-  constructor(options) {
-    validateOptions(options);
+  constructor(optionsIn) {
+    validateOptions(optionsIn);
+    const options = {
+      ...optionsIn,
+      headers: {
+        ...optionsIn.headers,
+        ...optionsIn.companionOptions.uploadHeaders,
+      },
+    };
     this.providerName = options.providerName;
     this.options = options;
     this.token = randomUUID();
@@ -547,7 +554,7 @@ export default class Uploader {
     }
     try {
       const httpMethod = (this.options.httpMethod || "").toUpperCase() === "PUT" ? "put" : "post";
-      const runRequest = await got[httpMethod];
+      const runRequest = got[httpMethod];
       const response = await runRequest(url, reqOptions);
       if (this.size != null && bytesUploaded !== this.size) {
         const errMsg = `uploaded only ${bytesUploaded} of ${this.size} with status: ${response.statusCode}`;
diff --git a/packages/@uppy/companion/lib/standalone/helper.js b/packages/@uppy/companion/lib/standalone/helper.js
index a5f931f..fbba5f2 100644
--- a/packages/@uppy/companion/lib/standalone/helper.js
+++ b/packages/@uppy/companion/lib/standalone/helper.js
@@ -195,6 +195,9 @@ const getConfigFromEnv = () => {
     corsOrigins: getCorsOrigins(),
     testDynamicOauthCredentials: process.env.COMPANION_TEST_DYNAMIC_OAUTH_CREDENTIALS === "true",
     testDynamicOauthCredentialsSecret: process.env.COMPANION_TEST_DYNAMIC_OAUTH_CREDENTIALS_SECRET,
+    uploadHeaders: process.env.COMPANION_UPLOAD_HEADERS
+      ? JSON.parse(process.env.COMPANION_UPLOAD_HEADERS)
+      : undefined,
   };
 };
 /**

mifi added 4 commits November 3, 2025 12:38
(instead of *after* all tests)
this makes tests independent (not depending on mocks from previous tests)
this also uncovered bugs in tests which have been fixed
remove duplicate (and broken) test 'dropbox'
remove workaround for test "upload functions with xhr protocol"
@mifi mifi requested a review from Murderlon November 3, 2025 08:32
mifi added a commit to transloadit/uppy.io that referenced this pull request Nov 3, 2025
Copy link
Member

@Murderlon Murderlon left a comment

Choose a reason for hiding this comment

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

Don't forget the changeset, ideally also explaining there what this feature does

New Companion option `uploadHeaders` allows inclusion of static headers for all upload requests.
@mifi mifi merged commit 0c8dd19 into main Nov 3, 2025
12 checks passed
@mifi mifi deleted the companion-upload-headers branch November 3, 2025 10:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

uploadMultipart invoked from e.g. Dropbox plugin is not secured

3 participants