File Upload Questions

1

My question is regarding Uploading Files using the link

I have the following JS code

$('#arquivoCliente').fileinput({
            language: 'pt-BR',
            uploadAsync: false,
            showPreview: false,
            maxFileSize: 200,
            uploadUrl: 'upload.php',
            allowedFileExtensions : ['PDF', 'pdf']
            uploadExtraData: function() {
                return {
                    id: tempIDCliente
                };
            }
        });

My php is all ok, it's saving the file and everything. What I can not do is. As you can see my code is set to accept only the PDF extension. If the user chooses another extension, the send button is disabled.

But this option is only working if I comment the uploadUrl line, as in the example below.

$('#arquivoCliente').fileinput({
            language: 'pt-BR',
            uploadAsync: false,
            showPreview: false,
            maxFileSize: 200,
            // uploadUrl: 'upload.php',
            allowedFileExtensions : ['PDF', 'pdf']
            uploadExtraData: function() {
                return {
                    id: tempIDCliente
                };
            }
        });

Not commented yet

Reviewedassuch

    
asked by anonymous 03.07.2017 / 15:05

1 answer

1

I do not know if it's the right one, but I managed to work around it like this.

$('#arquivoCliente').fileinput({
            language: 'pt-BR',
            uploadAsync: true,
            showPreview: false,
            maxFileSize: 200,
            uploadUrl: 'upload.php',
            allowedFileExtensions : ['PDF', 'pdf'],
            uploadExtraData: function() {
                return {
                    id: tempIDCliente
                };
            }
        });

        $('#arquivoCliente').on('fileuploaded', function(event, data, previewId, index) {
            var form = data.form, files = data.files, extra = data.extra,
                response = data.response, reader = data.reader;
            console.log('File uploaded triggered');
            $('#arquivoCliente').fileinput('clear'); // Essas três linhas uso para atualizar o campo após o update
            $('#arquivoCliente').fileinput('refresh');
            $('#arquivoCliente').fileinput('enable');


        });

        //aqui testa se o arquivo é PDF e dentro do tamanho máximo estipulado

        $('#arquivoCliente').on('fileuploaderror', function(event, data, msg) {
            var form = data.form, files = data.files, extra = data.extra,
                response = data.response, reader = data.reader;
            console.log('File upload error');
           alerta(msg, 'danger');
           $('.fileinput-upload-button').attr('disabled', 'disabled'); // Desabilito o botão de upload manualmente
        });
    
03.07.2017 / 16:11