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

acceptedFiles is not respected for S3 upload #300

Open
pkid169 opened this issue Mar 7, 2018 · 12 comments
Open

acceptedFiles is not respected for S3 upload #300

pkid169 opened this issue Mar 7, 2018 · 12 comments

Comments

@pkid169
Copy link

pkid169 commented Mar 7, 2018

I'm following the example for S3 direct upload, and I've also specified acceptedFiles in the dropzoneOptions config object. I can see the uploaded file shown as an error, however it actually was still uploaded successfully on to my S3 bucket. Here's my code:

// Component
<vue-dropzone
	ref="myVueDropzone"
	id="dropzone"
	:awss3="awss3"
	:options="dropzoneOptions"
	@vdropzone-error="dropzoneError"
	v-on:vdropzone-s3-upload-error="s3UploadError"
	v-on:vdropzone-s3-upload-success="s3UploadSuccess"></vue-dropzone>

// Dropzone config object
dropzoneOptions: {
	url: 'https://httpbin.org/post',
	thumbnailWidth: 150,
	maxFilesize: 0.5,
	acceptedFiles: 'image/png'
}

// Event handlers
s3UploadError(errorMessage) {
	console.error('error: ', errorMessage);
},
s3UploadSuccess(s3ObjectLocation) {
	console.log('success: ', s3ObjectLocation);
},

What I saw on UI:
UI

Console log:
Console

@vrajroham
Copy link
Collaborator

vrajroham commented Mar 7, 2018 via email

@pkid169
Copy link
Author

pkid169 commented Mar 7, 2018

Sorry I realized I didn't phrase my question clearly. I actually uploaded a file that has a non-accepted extension so I was expecting to see the error (which is correct on the UI) and the file shouldn't have been sent successfully to S3 (but it was).

@pkid169
Copy link
Author

pkid169 commented Mar 7, 2018

FWIW, the same issue applies to max size allowed config option too (i.e. if I try to upload a file that's larger than the allowed size, it'll be shown as an error on the UI. However the file is still actually uploaded to S3).

Also if I don't use the provided S3 direct upload functionality (i.e. do not use the :awss3 option), and just go with the basic setup and provide my own AWS creds through dropzone config, it works as expected for both test case (i.e. if I upload a non supported file type/ larger than allowed file size, it throws an error and the file is NOT uploaded on S3). So I reckon there must be some code for the in-built S3 upload that ignores the error and still go ahead with the actual uploading?

@vrajroham
Copy link
Collaborator

Thanks for reporting this. We will look into this. +1

@vesper8
Copy link

vesper8 commented May 27, 2018

same thing happens with the accept method

for example:

        accept(file, done) {
          console.log(file.name);
          if (file.name === 'large.png') {
            const errMsg = "Naha, you don't.";
            console.log(errMsg);
            done(errMsg);
          } else { done(); }
        },

as per the docs, if I try to upload a file called 'large.png' it should reject the upload. I confirm that it does go inside the method and does go into the if that should reject the upload, however it has no impact and the file is uploaded anyway

I suspect this is also why the renameFile method does nothing as well when uploading to S3

@Rob89
Copy link

Rob89 commented Aug 13, 2018

I'm also hitting this issue. I have a workaround that seems to work until this is fixed properly.

Add a handler for the vdropzone-sending event:

v-on:vdropzone-sending="sending"

In that function, check if the file is accepted. If it's not, cancel the request to S3.

sending: function(file) {
    if (!file.accepted) {
        // abort doesn't work. Setting the timeout is the only thing I've found that cancels the s3 request. 
        file.xhr.timeout = 1;
    }
}

@vinayakkulkarni
Copy link

@vrajroham Any progress on this?

@vrajroham
Copy link
Collaborator

vrajroham commented Jan 18, 2019

@vrajroham Any progress on this?

Hey, @vinayakkulkarni not yet honestly! Will be fixing this soon and will update here.

@ganicus
Copy link

ganicus commented Sep 24, 2019

The issue is in the vue-dropzone.vue component file on line 415 at the end of a conditional in the getSignedAndUploadToS3 method.

      } else {
        promise.then(() => {
          setTimeout(() => this.dropzone.processFile(file));
        });
      }

The processFile function called and doesn't check file.accepted status. Error status files are processed as normal.

      } else {
        promise.then(() => {
          if(file.status != Dropzone.QUEUED) return 
          setTimeout(() => this.dropzone.processFile(file));
        });
      }

@aaronhuisinga
Copy link

@vrajroham This is definitely still an issue with a simple fix. Would love to get a PR merged with @ganicus proposed code change!

@bjensen
Copy link

bjensen commented Apr 11, 2020

Seams like this is still an issue. Can anyone else confirm?

@rowanwins
Copy link
Owner

Resolved in #549

@rowanwins rowanwins added this to the v3.7 milestone May 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants