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

examples/aws-nodejs: merge multipart and non-multipart examples #4521

Merged
merged 3 commits into from
Jun 28, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 11 additions & 25 deletions examples/aws-nodejs/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@
</head>
<body>
<h1>AWS upload example</h1>
<h2>AWS S3 (non multipart)</h2>
<div id="aws-non-multipart"></div>
<h2>AWS S3 multipart</h2>
<div id="aws-multipart"></div>
<div id="uppy"></div>
<script type="module">
import { Uppy, Dashboard, AwsS3Multipart, AwsS3 } from "https://releases.transloadit.com/uppy/v3.10.0/uppy.min.mjs"
import { Uppy, Dashboard, AwsS3 } from "https://releases.transloadit.com/uppy/v3.10.0/uppy.min.mjs"
{
const MiB = 0x10_00_00;

const uppy = new Uppy()
.use(Dashboard, {
inline: true,
target: '#aws-non-multipart',
target: '#uppy',
})
.use(AwsS3, {
// Files that are more than 100MiB should be uploaded in multiple parts.
shouldUseMultipart: (file) => file.size > 100 * MiB,

async getUploadParameters (file) {
// Send a request to our Express.js signing endpoint.
const response = await fetch('/sign-s3', {
Expand All @@ -44,30 +46,14 @@ <h2>AWS S3 multipart</h2>
return {
method: data.method,
url: data.url,
fields: data.fields, // For presigned PUT uploads, this should be left empty.
fields: {}, // For presigned PUT uploads, this should be left empty.
// Provide content type header required by S3
headers: {
'Content-Type': file.type,
},
}
},
});

uppy.on('complete', (result) => {
console.log('Upload complete! We’ve uploaded these files:', result.successful)
})

uppy.on('upload-success', (file, data) => {
console.log('Upload success! We’ve uploaded this file:', file.meta['name'])
})
}
{
const uppy = new Uppy()
.use(Dashboard, {
inline: true,
target: '#aws-multipart',
})
.use(AwsS3Multipart, {

async createMultipartUpload(file, signal) {
if (signal?.aborted) {
const err = new DOMException('The operation was aborted', 'AbortError')
Expand Down Expand Up @@ -179,7 +165,7 @@ <h2>AWS S3 multipart</h2>
const data = await response.json()

return data
}
},
})

uppy.on('complete', (result) => {
Expand Down