Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

example: fix aws-companion example #3850

Merged
merged 4 commits into from Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Expand Up @@ -191,6 +191,7 @@ module.exports = {
files: [
'*.mjs',
'e2e/clients/**/*.js',
'examples/aws-companion/*.js',
'examples/aws-presigned-url/*.js',
'examples/bundled/*.js',
'examples/custom-provider/client/*.js',
Expand Down
2 changes: 1 addition & 1 deletion examples/aws-companion/.gitignore
@@ -1 +1 @@
uppy.min.css
tmp
23 changes: 23 additions & 0 deletions examples/aws-companion/README.md
@@ -0,0 +1,23 @@
# Uppy + AWS S3 Example

This example uses @uppy/companion with a custom AWS S3 configuration.
Files are uploaded to a randomly named directory inside the `whatever/`
directory in a bucket.

## Run it

First, set up the `COMPANION_AWS_KEY`, `COMPANION_AWS_SECRET`,
`COMPANION_AWS_REGION`, and `COMPANION_AWS_BUCKET` environment variables for
`@uppy/companion` in a `.env` file. You may find useful to first copy the
`.env.example` file:

```sh
[ -f .env ] || cp .env.example .env
```

To run this example, from the **repository root**, run:

```sh
corepack yarn install
corepack yarn workspace @uppy-example/aws-companion start
```
3 changes: 1 addition & 2 deletions examples/aws-companion/index.html
Expand Up @@ -4,9 +4,8 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Companion + AWS Example</title>
<link href="uppy.min.css" rel="stylesheet">
</head>
<body>
<script src="bundle.js"></script>
<script src="./main.js" type="module"></script>
</body>
</html>
14 changes: 9 additions & 5 deletions examples/aws-companion/main.js
@@ -1,8 +1,12 @@
const Uppy = require('@uppy/core')
const GoogleDrive = require('@uppy/google-drive')
const Webcam = require('@uppy/webcam')
const Dashboard = require('@uppy/dashboard')
const AwsS3 = require('@uppy/aws-s3')
import AwsS3 from '@uppy/aws-s3'
import Uppy from '@uppy/core'
import Dashboard from '@uppy/dashboard'
import GoogleDrive from '@uppy/google-drive'
import Webcam from '@uppy/webcam'

import '@uppy/core/dist/style.css'
import '@uppy/dashboard/dist/style.css'
import '@uppy/webcam/dist/style.css'

const uppy = new Uppy({
debug: true,
Expand Down
29 changes: 16 additions & 13 deletions examples/aws-companion/package.json
@@ -1,30 +1,33 @@
{
"name": "@uppy-example/aws-companion",
"version": "0.0.0",
"type": "module",
"dependencies": {
"@babel/core": "^7.2.2",
"@uppy/aws-s3": "workspace:*",
"@uppy/core": "workspace:*",
"@uppy/dashboard": "workspace:*",
"@uppy/google-drive": "workspace:*",
"@uppy/webcam": "workspace:*",
"babelify": "^10.0.0",
"body-parser": "^1.18.3",
"budo": "^11.6.1",
"@uppy/webcam": "workspace:*"
},
"devDependencies": {
"@uppy/companion": "workspace:*",
"body-parser": "^1.20.0",
"cookie-parser": "^1.4.6",
"cors": "^2.8.5",
"express": "^4.16.4",
"express-session": "^1.15.6",
"npm-run-all": "^4.1.5"
"dotenv": "^16.0.1",
"express": "^4.18.1",
"express-session": "^1.17.3",
"npm-run-all": "^4.1.5",
"vite": "^2.7.1"
},
"private": true,
"engines": {
"node": ">=14.14.0"
"node": ">=16.15.0"
},
"scripts": {
"copy": "cp ../../packages/uppy/dist/uppy.min.css .",
"start": "npm-run-all --serial copy --parallel start:*",
"start:client": "budo main.js:bundle.js -- -t babelify",
"start:server": "node server.js"
"dev": "vite",
"start": "npm-run-all --parallel start:client start:server",
"start:client": "vite",
"start:server": "node server.cjs"
}
}
23 changes: 0 additions & 23 deletions examples/aws-companion/readme.md

This file was deleted.

@@ -1,18 +1,23 @@
const fs = require('node:fs')
const path = require('node:path')
const companion = require('../../packages/@uppy/companion')
const companion = require('@uppy/companion')
aduh95 marked this conversation as resolved.
Show resolved Hide resolved

require('dotenv').config({ path: path.join(__dirname, '..', '..', '.env') })
const app = require('express')()

const DATA_DIR = path.join(__dirname, 'tmp')

app.use(require('cors')({
origin: true,
origin: 'http://localhost:3000',
methods: ['GET', 'POST', 'OPTIONS'],
credentials: true,
}))
app.use(require('cookie-parser')())
app.use(require('body-parser').json())
app.use(require('express-session')({
secret: 'hello planet',
saveUninitialized: false,
resave: false,
}))

const options = {
Expand All @@ -21,14 +26,14 @@ const options = {
key: process.env.COMPANION_GOOGLE_KEY,
secret: process.env.COMPANION_GOOGLE_SECRET,
},
s3: {
getKey: (req, filename) => `whatever/${Math.random().toString(32).slice(2)}/${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: process.env.COMPANION_AWS_ENDPOINT,
},
},
s3: {
getKey: (req, filename) => `${crypto.randomUUID()}-${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: process.env.COMPANION_AWS_ENDPOINT,
},
server: { host: 'localhost:3020' },
filePath: DATA_DIR,
Expand Down