question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

onBeforeFileAdded callback issue

See original GitHub issue

Hi, I work on image upload, and I have a restrictions on allowedFileTypes and maxFileSide. My onBeforeFileAdded looks like:

  onBeforeFileAdded: (currentFile, files) => {
    debugger
    if (currentFile.data.size > uppy.opts.restrictions.maxFileSize) {
      ...
    }

When I choose file temp.img that violates restrictions, the callback onBeforeFileAdded is called and it stops on debugger. Then I let debugger to go, and everything is fine

Then I chose the same file temp.img that violates restrictions, the callback onBeforeFileAdded it do not stop on debugger, in other words it is not called at all.

Then i chose some other file like temp_222.img file that violates restrictions, the callback onBeforeFileAdded is called and it stops on debugger.

Thanks! 😃 and

Here is my config:

$().ready(function() {
  var uppy = Uppy.Core({
  debug: true,
  autoProceed: true,
  restrictions: {
    maxFileSize: 1000,
    maxNumberOfFiles: false,
    minNumberOfFiles: false,
    allowedFileTypes: ['image/*']
  },
  onBeforeFileAdded: (currentFile, files) => {
    debugger

    if (currentFile.data.size > uppy.opts.restrictions.maxFileSize) {
      const message = `Error: ${currentFile.name} file exceeds maximum allowed size of 20 MB.`;
      const timeStamp = Date.now();

      $('.Informer').append( "<p class='" + timeStamp + " link'> " + message + "</p>").find("." + 
          timeStamp).delay(10000).slideUp();
      // return false
    }
  },
  })
  .use(Uppy.FileInput, {
    target: '.DashboardContainer',
    allowMultipleFiles: true,
    pretty: true,
    inputName: 'files[]',
    locale: {
      strings: {
        chooseFiles: 'Select to upload'
      }
    }
  })
  .use(Uppy.ThumbnailGenerator)
  .use(Uppy.ProgressBar, {
    target: '.DashboardContainerStatusBar',
  })
  .use(Uppy.AwsS3, {...})
  .run()

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
lakesarecommented, May 24, 2019

@goto-bus-stop, we still have this issue, in that if we try to select the same file twice, - onBeforeFileAdded() is not called the second time (and is called again for this file if we try to select some completely different file in between the attempts). I will look into it!

1reaction
jerko-culinacommented, Apr 19, 2018

Thanks on replay, I’m also not sure if this is issue, but I tried next:

First I choose file temp.img that violates restrictions, the callback onBeforeFileAdded is called and it stops on debugger.

Second I choose file temp.img that violates restrictions, the callback onBeforeFileAdded is not called and it do not stops on debugger.

Third I choose file temp_222.img that violates restrictions, the callback onBeforeFileAdded is called and it stops on debugger.

Fourth I choose file temp.img that violates restrictions, the callback onBeforeFileAdded is called and it stops on debugger.


I really don’t know if it is issue or not but for me this behaviour is a little unusual. In Fourth example if it didn’t call the onBeforeFileAdded callback it would be ok, but on this way it is unusual.

If You’re going to plan something about this, please notify me about your decision. Thank You! 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

const - Uppy
onBeforeFileAdded : (currentFile, files) => currentFile. A function run before a file is added to Uppy. It gets passed (currentFile, files) where currentFile...
Read more >
How to rename a file in uppy? javascript - Stack Overflow
You need to make sure that the callback you posted is passed into your main uppy core initialization. It should work then as...
Read more >
Limit uploader max file size? - Webix Forum
I have a problem with my upload logic. IIS (Microsoft) returns a ... However, webix does not catch this in the callback of...
Read more >
@filerobot/core - npm
Core module for the extensible JavaScript file upload widget with support for drag&drop, resumable uploads, previews, restrictions, file processing/encoding ...
Read more >
transloadit - Bountysource
const minFileSize = 1 * 1024 * 1024; //1MB onBeforeFileAdded: ... Not sure if the issue related to uppy companion itself or to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found