Skip to content

Instantly share code, notes, and snippets.

@shriharip
Created September 13, 2023 16:29
Show Gist options
  • Save shriharip/e189230a90bb96b34fcc959b339f2685 to your computer and use it in GitHub Desktop.
Save shriharip/e189230a90bb96b34fcc959b339f2685 to your computer and use it in GitHub Desktop.
Uppy companion example
const fs = require('node:fs')
const path = require('node:path')
const crypto = require('node:crypto')
const companion = require('@uppy/companion')
require('dotenv').config({ path: path.join(__dirname, '.env') })
const app = require('express')()
const DATA_DIR = path.join(__dirname, 'tmp')
app.use(require('cors')({
origin: '*',
methods: ['GET', 'POST', 'OPTIONS'],
credentials: true,
}))
app.use(require('cookie-parser')())
app.use(require('body-parser').json())
app.use(require('express-session')({
secret: 'hello secret',
saveUninitialized: false,
resave: false,
}))
const options = {
providerOptions: {
instagram: {
key: '',
secret: '',
},
},
s3: {
getKey: (req, filename, metadata) => { console.log('the metadata info is ', metadata); return `${metadata.userId}/${filename}`},
key: process.env.COMPANION_AWS_KEY,
secret: process.env.COMPANION_AWS_SECRET,
bucket: process.env.COMPANION_AWS_BUCKET,
region: process.env.COMPANION_AWS_REGION,
endpoint: 'https://{region}.digitaloceanspaces.com',
acl: 'public-read'
},
uploadUrls: ['https://app.fra1.digitaloceanspaces.com'],
server: { host: 'domain.app', protocol: 'https' },
filePath: DATA_DIR,
secret: 'laki govi',
debug: true,
}
// Create the data directory here for the sake of the example.
try {
fs.accessSync(DATA_DIR)
} catch (err) {
fs.mkdirSync(DATA_DIR)
}
process.on('exit', () => {
fs.rmSync(DATA_DIR, { recursive: true, force: true })
})
const { app: companionApp } = companion.app(options)
app.use(companionApp)
app.get('/', (req, res)=> {
res.send('HELLO G')
})
app.get('/', (req, res)=> {
res.type('.html')
res.sendFile(path.join(__dirname, '..', '/client/index.html'));
})
const server = app.listen(3020, () => {
console.log('listening on port 3020')
})
companion.socket(server)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment