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

Uploading only valid images #822

Closed
koxu1996 opened this issue Dec 26, 2016 · 12 comments
Closed

Uploading only valid images #822

koxu1996 opened this issue Dec 26, 2016 · 12 comments

Comments

@koxu1996
Copy link
Contributor

koxu1996 commented Dec 26, 2016

Curretly when eg. minImageWidth is setted and user select both correct and incorrect files he is still able to click upload button:

and it trigger uploading for every file:

The problem is that on server side when $_FILES['input'] is empty, we cannot simply return {'error':'No files found for upload.'}, because $_FILES['input'] is also empty when invalid file is uploaded. Let's tell we will return {} in this case, but there is next problem: when resizeImage is true and invalid file is uploaded, on server we always receive filename blob. So again we can return {} when filename is blob, but this has drawback that server cannot handle correct files which has this name.

I think extension should skip uploading invalid files and this will simplify implementing server-side. What about changing upload() to check whether file frame has class file-preview-error or something like this?

@kartik-v
Copy link
Owner

The plugin does not send any FILES for upload to server when validation error is encountered (as is expected and as you mentioned $_FILES['input'] is received empty on the server).

So yes this is a logic to be more handled at your server end ...as you mentioned for your specific use case - whenever files are received empty at server end.

On the resizeImage part - the plugin relies on the canvas-to-blob third party plugin by blueimp... check if there is any config there to handle an invalid file for blob conversion... and I will keep it open for enhancement.

@koxu1996
Copy link
Contributor Author

You problably did not understand what I had on my mind. Do you agree that FILES should be empty always when error is encountered, even if resizeImage is true?

@koxu1996
Copy link
Contributor Author

koxu1996 commented Dec 27, 2016

While trying to debug this problem I ran into another one: fiddle

@kartik-v
Copy link
Owner

New enhancements have been added for preventing upload when data is empty. New property msgUploadEmpty available that will show the message when one tries to upload data without any data (it will validate both files data as well as uploadExtra to get to this condition).

@koxu1996
Copy link
Contributor Author

It solve issue only in small part. I want to explain you this issue, can we talk by hangout/skype?

@kartik-v
Copy link
Owner

Suppose you mean issue #823... its resolved there.

@koxu1996
Copy link
Contributor Author

Your enhancement along with fixed #823 resolved issue. Now everything is working fine 👍

@koxu1996
Copy link
Contributor Author

koxu1996 commented Dec 29, 2016

@kartik-v I was wrong, there is still one problem. Consider resizeImage:true and one of selected images invalid. Now fileimagesresized is not called, because increasing counter is skipped by this https://github.com/kartik-v/bootstrap-fileinput/blob/master/js/fileinput.js#L2578
In my opinion this event should be called after all resizing jobs are done, NOT if there was as many resizes as uploaded images. So even if upload one invalid image, we should get fileimagesresized, which inform us, that no one resizing process is running and no one will be.
What about just adding counter.val++; before return true;?

kartik-v added a commit that referenced this issue Dec 30, 2016
@koxu1996
Copy link
Contributor Author

@kartik-v Now it is working, except case when last image is invalid. I forgot to mention that you should add this code after increasing counter:

if (counter.val === num_imgs) {
    self._raise('fileimagesresized');
}

@koxu1996
Copy link
Contributor Author

@kartik-v I was wrong, issue still persist. Lets select one invalid with one valid image and click upload. Then we get request for each image, even for invalid. Now we can only click "cancel" button and after uploading next valid image previous dissapear! You can watch it on video.

What is the reason for uploading invalid images? Can just upload function skip invalid images or delete them?

@koxu1996
Copy link
Contributor Author

@kartik-v What about this?

@kartik-v
Copy link
Owner

Not got the time to check this.. will update... once I get time.

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

2 participants