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

Event onBeforeUpload Async #1592

Closed
guiraamos opened this issue May 23, 2019 · 2 comments
Closed

Event onBeforeUpload Async #1592

guiraamos opened this issue May 23, 2019 · 2 comments
Assignees
Labels

Comments

@guiraamos
Copy link

Hi !

I'm trying to perform an async request on the onBeforeUpload commit, but I can not. How should I carry out these cases?

In my example, I make a call to an API that returns an ID, this ID I update the metadata of the files to do the processing on the file server using the TUS protocol.

@guiraamos guiraamos added Not Accepted We cannot accept this issue, please read https://uppy.io/support Triage labels May 23, 2019
@arturi arturi added Question and removed Not Accepted We cannot accept this issue, please read https://uppy.io/support Triage labels May 24, 2019
@jazkh
Copy link

jazkh commented May 24, 2019

onBeforeUpload is a method of an object.

Please show your code to know what have you tried so far.

Here is an example from official docs:

onBeforeUpload: async function (files) {
const updatedFiles = await Object.assign({}, files)
await Object.keys(updatedFiles).forEach(fileId => {
updatedFiles[fileId].name = 'myCustomPrefix_' + updatedFiles[fileId].name
})
return updatedFiles
}

@arturi
Copy link
Contributor

arturi commented Jul 16, 2019

Hi! Sorry for the long delay with my reply. onBeforeUpload is meant for sync checks/work. For async, it’s better to implement a small custom Uppy plugin, we’ve added this info to the docs.

Here’s an example of a small custom plugin that compresses images before upload: https://uppy.io/docs/writing-plugins/#Example-of-a-custom-plugin. In the same manner you can make the call to your API and update files accordingly. Please let me know if this works for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants