Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

chore: some tus demo improcements.

thorwebdev1a2fbd7b93ee
diff --git a/examples/storage/resumable-upload-uppy/README.md b/examples/storage/resumable-upload-uppy/README.md
index 2cf6049cf5d..bbf4c94a6e4 100644
--- a/examples/storage/resumable-upload-uppy/README.md
+++ b/examples/storage/resumable-upload-uppy/README.md
@@ -1,19 +1,22 @@
-## Resumable Upload with Supabase Storage and Uppy
+## Resumable Uploads with Supabase Storage and Uppy
-This example shows how to use [Supabase Storage](https://supabase.io/docs/reference/javascript/storage) with [Uppy](https://uppy.io/) to upload files to Supabase Storage using
-the TUS protocol (resumable uploads).
+This example shows how to use [Supabase Storage](https://supabase.io/docs/reference/javascript/storage) with [Uppy](https://uppy.io/) to upload files to Supabase Storage using the TUS protocol (resumable uploads).
### Running the example
- Create a supabase bucket from the Supabase UI
+- Add a policy to allow public uploads
+ - e.g. `CREATE POLICY "allow uploads" ON storage.objects FOR INSERT TO public WITH CHECK (bucket_id = 'your-bucket-name');`
- Open the index.html file and replace the following variables with your own:
```js
-const token = '' // jwt token or service role key
-const project = '' // supabase project id
-const bucketName = '' // supabase bucket name
+const SUPABASE_ANON_KEY = '' // your project's anon key
+const SUPABASE_PROJECT_ID = '' // your project ref
+const STORAGE_BUCKET = '' // your storage bucket name
```
+Serve the index.html file locally (e.g. with Python Simple HTTP Server) and start uploading:
-
-Open the index.html on your browser and start uploading files.
\ No newline at end of file
+```bash
+python3 -m http.server
+```
diff --git a/examples/storage/resumable-upload-uppy/index.html b/examples/storage/resumable-upload-uppy/index.html
index 213f61ca3bf..1cbf59242d2 100644
--- a/examples/storage/resumable-upload-uppy/index.html
+++ b/examples/storage/resumable-upload-uppy/index.html
@@ -1,82 +1,95 @@
-<!doctype html>
+<!DOCTYPE html>
<html>
-<head>
- <meta charset="utf-8">
+ <head>
+ <meta charset="utf-8" />
<title>Resumable Upload Supabase + UppyJS</title>
- <link href="https://releases.transloadit.com/uppy/v3.6.1/uppy.min.css" rel="stylesheet">
+ <link href="https://releases.transloadit.com/uppy/v3.6.1/uppy.min.css" rel="stylesheet" />
<style>
- html {
- background: #9e44ef;
- }
- body {
- height: 100vh;
- background: radial-gradient(72.03% 66.03% at 50% 69.72%,#dbb8bf 0,transparent 100%);
- display: flex;
- align-items: center;
- justify-content: center;
- flex-direction: column;
- }
-
- #drag-drop-area {
- margin-top: 40px;
- }
+ html {
+ background: #9e44ef;
+ }
+ body {
+ height: 100vh;
+ background: radial-gradient(72.03% 66.03% at 50% 69.72%, #dbb8bf 0, transparent 100%);
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ flex-direction: column;
+ }
+ a {
+ display: block;
+ margin: 10px;
+ text-decoration: none;
+ }
+ #logo {
+ max-width: 150px;
+ }
+ #drag-drop-area {
+ margin-top: 40px;
+ }
</style>
-</head>
-<body>
-<img src="supabase-logo-wordmark--dark.webp">
-<div id="drag-drop-area"></div>
-
-<script type="module">
- import {Uppy, Dashboard, Tus} from "https://releases.transloadit.com/uppy/v3.6.1/uppy.min.mjs"
+ </head>
+ <body>
+ <img id="logo" src="supabase-logo-wordmark--dark.png" />
+ <div id="drag-drop-area"></div>
+ <a href="https://supabase.com/docs/guides/storage/uploads#resumable-upload" target="_blank"
+ >Read the docs.</a
+ >
- const token = ''
- const project = ''
- const bucketName = ''
+ <script type="module">
+ import {
+ Uppy,
+ Dashboard,
+ Tus,
+ } from 'https://releases.transloadit.com/uppy/v3.6.1/uppy.min.mjs'
+ const SUPABASE_ANON_KEY = 'repace-with-your-anon-key'
+ const SUPABASE_PROJECT_ID = 'repace-with-your-project-id'
+ const STORAGE_BUCKET = 'repace-with-your-bucket-id'
- const folder = ''
- const supabaseStorageURL = `https://${project}.supabase.co/storage/v1/upload/resumable`
+ const folder = ''
+ const supabaseStorageURL = `https://${SUPABASE_PROJECT_ID}.supabase.co/storage/v1/upload/resumable`
- var uppy = new Uppy()
+ var uppy = new Uppy()
.use(Dashboard, {
- inline: true,
- limit: 10,
- target: '#drag-drop-area',
- showProgressDetails: true,
+ inline: true,
+ limit: 10,
+ target: '#drag-drop-area',
+ showProgressDetails: true,
})
.use(Tus, {
- endpoint: supabaseStorageURL,
- headers: {
- authorization: `Bearer ${token}`,
- apikey: token,
- },
- uploadDataDuringCreation: true,
- chunkSize: 6 * 1024 * 1024,
- allowedMetaFields: ['bucketName', 'objectName', 'contentType', 'cacheControl'],
- onError: function (error) {
- console.log("Failed because: " + error)
- },
+ endpoint: supabaseStorageURL,
+ headers: {
+ authorization: `Bearer ${SUPABASE_ANON_KEY}`,
+ apikey: SUPABASE_ANON_KEY,
+ },
+ uploadDataDuringCreation: true,
+ chunkSize: 6 * 1024 * 1024,
+ allowedMetaFields: ['bucketName', 'objectName', 'contentType', 'cacheControl'],
+ onError: function (error) {
+ console.log('Failed because: ' + error)
+ },
})
- uppy.on('file-added', (file) => {
+ uppy.on('file-added', (file) => {
const supabaseMetadata = {
- bucketName: bucketName,
- objectName: folder ? `${folder}/${file.name}` : file.name,
- contentType: file.type,
+ bucketName: STORAGE_BUCKET,
+ objectName: folder ? `${folder}/${file.name}` : file.name,
+ contentType: file.type,
}
file.meta = {
- ...file.meta,
- ...supabaseMetadata,
+ ...file.meta,
+ ...supabaseMetadata,
}
console.log('file added', file)
- })
+ })
- uppy.on('complete', (result) => {
+ uppy.on('complete', (result) => {
console.log('Upload complete! We’ve uploaded these files:', result.successful)
- })
-</script>
-</body>
-</html>
\ No newline at end of file
+ })
+ </script>
+ </body>
+</html>
diff --git a/examples/storage/resumable-upload-uppy/supabase-logo-wordmark--dark.png b/examples/storage/resumable-upload-uppy/supabase-logo-wordmark--dark.png
new file mode 100644
index 00000000000..dccffd4247d
Binary files /dev/null and b/examples/storage/resumable-upload-uppy/supabase-logo-wordmark--dark.png differ