Skip to content

Commit

Permalink
Merge pull request #7 from imagekit-developer/dev
Browse files Browse the repository at this point in the history
IMAGEKIT-717: Batch upload
  • Loading branch information
nikniv authored Sep 14, 2022
2 parents e5b0bce + 23e83a9 commit d6767b5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,31 @@ const uppy = Uppy({ debug: true, autoProceed: false })
]
})
```
# Enable batch upload

You can use the `limit` parameter to enable batch processing and set the batch size for upload. By default, all upload requests are sent simultaneously.

In the following example, the selected files would be uploaded in batches, with each batch having a maximum of 10 files.

``` javascript
import Uppy from '@uppy/core'
import '@uppy/core/dist/style.css'
import '@uppy/dashboard/dist/style.css'
import Dashboard from '@uppy/dashboard'
import ImageKitUppyPlugin from "imagekit-uppy-plugin"

const uppy = Uppy({ debug: true, autoProceed: false })
.use(Dashboard, {
inline: true,
trigger: '#uppyDashboard', // your element
})
.use(ImageKitUppyPlugin, {
id: 'ImageKit',
authenticationEndpoint: `http://www.yourserver.com/auth`,
publicKey: "your_public_key",
limit: 10
})
```

# Support
If something doesn't work as expected, please reach out to us at [email protected] or create an issue in this repo. Please try to include a reproducible code sample.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "imagekit-uppy-plugin",
"version": "1.0.3",
"version": "1.0.4",
"description": "A plugin for Uppy, which allows you to upload files directly to ImageKit.io media library.",
"main": "dist/imagekit-uppy-plugin.cjs.js",
"module": "dist/imagekit-uppy-plugin.esm.js",
Expand Down
13 changes: 12 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,18 @@ class ImageKitUppyPlugin extends Plugin {
if (file.error) {
return Promise.reject(new Error(file.error))
} else {
return this.upload(file, current, total)
return new Promise((resolve, reject) => {
const queuedRequest = this.requests.run(() => {
this.upload(file, current, total)
.then((res) => {
queuedRequest.done()
resolve(res)
}).catch((err) => {
queuedRequest.done()
reject(err)
})
})
})
}
})

Expand Down

0 comments on commit d6767b5

Please sign in to comment.