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: migrate python-xhr to ESM #4010

Merged
merged 1 commit into from Aug 19, 2022
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -198,6 +198,7 @@ module.exports = {
'examples/multiple-instances/*.js',
'examples/node-xhr/*.js',
'examples/php-xhr/*.js',
'examples/python-xhr/*.js',
'examples/transloadit-markdown-bin/*.js',
'examples/xhr-bundle/*.js',
'private/dev/*.js',
Expand Down
3 changes: 1 addition & 2 deletions examples/python-xhr/.gitignore
@@ -1,2 +1 @@
uppy.min.css
uploads
uploads/
15 changes: 7 additions & 8 deletions examples/python-xhr/readme.md → examples/python-xhr/README.md
Expand Up @@ -6,22 +6,21 @@ This example uses a Python Flask server and `@uppy/xhr-upload` to upload files t

To run this example, make sure you've correctly installed the **repository root**:

```bash
npm install
npm run build
```sh
corepack yarn install
corepack yarn build
```

That will also install the npm dependencies for this example.

Additionally, this example uses python dependencies. Move into this directory, and install them using pip:

```bash
cd ./examples/python-xhr
pip install -r requirements.txt
```sh
corepack yarn workspace @uppy-example/python-xhr installPythonDeps
```

Then, again in the **repository root**, start this example by doing:

```bash
npm run example python-xhr
```sh
corepack yarn workspace @uppy-example/python-xhr start
```
4 changes: 2 additions & 2 deletions examples/python-xhr/index.html
Expand Up @@ -4,9 +4,9 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Python + Uppy Example</title>
<link href="uppy.min.css" rel="stylesheet">
</head>
<body>
<script src="bundle.js"></script>
<noscript>This app requires JavaScript.</noscript>
<script src="./main.js" type="module"></script>
</body>
</html>
12 changes: 8 additions & 4 deletions examples/python-xhr/main.js
@@ -1,7 +1,11 @@
const Uppy = require('@uppy/core')
const Webcam = require('@uppy/webcam')
const Dashboard = require('@uppy/dashboard')
const XHRUpload = require('@uppy/xhr-upload')
import Uppy from '@uppy/core'
import Webcam from '@uppy/webcam'
import Dashboard from '@uppy/dashboard'
import XHRUpload from '@uppy/xhr-upload'

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

const uppy = new Uppy({
debug: true,
Expand Down
22 changes: 10 additions & 12 deletions examples/python-xhr/package.json
@@ -1,24 +1,22 @@
{
"name": "@uppy-example/python-xhr",
"version": "0.0.0",
"type": "module",
"dependencies": {
"@babel/core": "^7.4.4",
"@uppy/core": "workspace:*",
"@uppy/dashboard": "workspace:*",
"@uppy/webcam": "workspace:*",
"@uppy/xhr-upload": "workspace:*",
"babelify": "^10.0.0",
"budo": "^11.3.2",
"cookie-parser": "^1.4.6",
"cors": "^2.8.4",
"formidable": "^1.2.1",
"npm-run-all": "^4.1.3"
"@uppy/xhr-upload": "workspace:*"
},
"devDependencies": {
"npm-run-all": "^4.1.3",
"vite": "^3.0.0"
},
"private": true,
"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": "mkdir -p uploads && python server.py"
"installPythonDeps": "python3 -m pip install -r requirements.txt",
"start": "npm-run-all --parallel start:server start:client",
"start:client": "vite",
"start:server": "mkdir -p uploads && python3 server.py"
}
}
5 changes: 3 additions & 2 deletions examples/python-xhr/server.py 100644 → 100755
@@ -1,3 +1,4 @@
#!/usr/bin/env python3
import os
from flask import Flask, request, jsonify
from werkzeug.utils import secure_filename
Expand All @@ -7,7 +8,7 @@
ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'])

app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
app.config['UPLOAD_FOLDER'] = os.path.join(os.path.dirname(__file__), UPLOAD_FOLDER)
CORS(app)

def allowed_file(filename):
Expand All @@ -18,7 +19,7 @@ def allowed_file(filename):
def upload_file():
if request.method == 'POST':
# check if the post request has the file part
print request.files
print (request.files)
if len(request.files) == 0:
return jsonify(
error="No file n request"
Expand Down
16 changes: 2 additions & 14 deletions yarn.lock
Expand Up @@ -8175,17 +8175,12 @@ __metadata:
version: 0.0.0-use.local
resolution: "@uppy-example/python-xhr@workspace:examples/python-xhr"
dependencies:
"@babel/core": ^7.4.4
"@uppy/core": "workspace:*"
"@uppy/dashboard": "workspace:*"
"@uppy/webcam": "workspace:*"
"@uppy/xhr-upload": "workspace:*"
babelify: ^10.0.0
budo: ^11.3.2
cookie-parser: ^1.4.6
cors: ^2.8.4
formidable: ^1.2.1
npm-run-all: ^4.1.3
vite: ^3.0.0
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -13695,7 +13690,7 @@ __metadata:
languageName: node
linkType: hard

"cors@npm:^2.8.4, cors@npm:^2.8.5, cors@npm:latest, cors@npm:~2.8.5":
"cors@npm:^2.8.5, cors@npm:latest, cors@npm:~2.8.5":
version: 2.8.5
resolution: "cors@npm:2.8.5"
dependencies:
Expand Down Expand Up @@ -18479,13 +18474,6 @@ __metadata:
languageName: node
linkType: hard

"formidable@npm:^1.2.1":
version: 1.2.6
resolution: "formidable@npm:1.2.6"
checksum: 2b68ed07ba88302b9c63f8eda94f19a460cef6017bfda48348f09f41d2a36660c9353137991618e0e4c3db115b41e4b8f6fa63bc973b7a7c91dec66acdd02a56
languageName: node
linkType: hard

"formidable@npm:^2.0.1":
version: 2.0.1
resolution: "formidable@npm:2.0.1"
Expand Down