Passing data between Uppy and Companion

Hi, I am using Uppy on my react client side and Companion on node.js. I’m trying to pass some data to my Companion from my client. I read about serverHeaders but am not quite sure how to use it.

Client-side code:

Uppy()
  .use(AwsS3, {
    limit: 2,
    companionUrl: 'http://localhost:5000',
    // some additional data here
  })

back-end

const options = {
  providerOptions: {
    s3: {
      getKey: (req, filename) => //data passed from client,
      key: process.env.AWS_ACCESS_KEY,
      secret: process.env.AWS_SECRET_KEY,
      bucket: 'honeybee-chat',
      region: 'us-east-1'
    }
  },
  server: {
    host: 'localhost:3000',
    protocol: 'http',
  },
  filePath: './downloads',
  secret: 'jgovipawajefa'
}

Also, is there a way to change the bucket destination based on information from the front-end?

Thanks

Figured it out:
It took me a while so I’ll provide a working example:

Uppy()
  .use(AwsS3, {
    limit: 2,
    serverHeaders: { 'extra-data': {participant_id: props.id, } },
    companionUrl: 'http://localhost:3000'
  })

Server:

//make sure you declare the name of the header you will pass in CORS! 
app.use(function (req, res, next) {
  res.header("Access-Control-Allow-Methods", "OPTIONS, GET, POST, PATCH, PUT")
  res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization, Extra-Data");
  next()
})

// then access inside of req.headers
1 Like