Redirect downloads as soon as allow one download in pre-access mode

I am wondering if this is possible using pre-loading perforations to limit the download of only one file by the user, currently I have:

 <p:fileUpload fileUploadListener="#{fileUploadController.handleFileUpload}"
                                  mode="advanced" 
                                  multiple="false" 
                                  update="messages"
                                  sizeLimit="100000000" 
                                  allowTypes="/(\.|\/)(gif|jpe?g|png|doc|docx|txt|pdf)$/"
                                  auto="false"/>


                    <p:growl id="messages" showDetail="true"/>

since you can see that I have muliple = "false", but the user can still upload multiple files, any tips?

EDIT:

                <p:fileUpload widgetVar="upload" fileUploadListener="#{fileUploadController.handleFileUpload}"
                              mode="advanced" 
                              multiple="false" 
                              update="messages"
                              label="Select File"
                              sizeLimit="100000000" 
                              allowTypes="/(\.|\/)(gif|jpe?g|png|doc|docx|txt|pdf|html)$/"
                              auto="false"/>


                <p:growl id="messages" showDetail="true"/>

added widgetVar above

and in my js

<script type="text/javascript"> 
        function Naviagtion()
        {
            //alert("Sent to the printing holding queue, you may close this app now, your work will still print out ");
            window.setTimeout(afterDelay, 500);
            location.href = 'FilesUploaded.xhtml';

        }

        upload.buttonBar.find('input[type=file]').change(function() {
            if (this.value) {
                var files = upload.uploadContent.find('.files tr');

                if (files.length > 1) {
                    files.get(0).remove();
                }
            }
        });
    </script>

but I can still download many times, I'm going to do it in the right direction

+5
source share
3 answers

multiple="false" - " ". , enduser "" PrimeFaces .

JS/jQuery . <p:fileUpload> a widgetVar="upload", :

$(document).ready(function() {
    upload.buttonBar.find('input[type=file]').change(function() {
        if (this.value) {
            var files = upload.uploadContent.find('.files tr');

            if (files.length > 1) {
                files.get(0).remove();
            }
        }
    });
});

PrimeFaces 3.5.

+8

, @BalusC, firstfaces 4.0

fileLimit="1"

1, "". ,

" "

+10

If you have set the file limit to 1 and some error occurs while downloading the file, you need to refresh the page to download the file again. If you do not refresh the page, you will receive an error message.

I used the solution with JS, as in the accepted answer, but I need to change the selector because wigetWar did not work for me.

In my opinion, I have:

<p:fileUpload id="objectUpload"... />

In my portlet topic, the file table has the css class "ui-fileupload-files".

$(document).ready(function() {
  $("div[id*='objectUpload']").find('input[type=file]').change(function() {

    if (this.value) {
        var files = $("div[id*='objectUpload']").find('.uifileupload-files tr');        
        if (files.length > 1) {     
            files.get(0).remove();
        }
    }
  });
});

Hope this helps. I used PrimeFaces 6.0

0
source

All Articles