How to check if after selecting a file the same still exists in the Javascript directory

Asked

Viewed 116 times

1

In my application I use as a javascript framework the Angularjs, and to select the files I use the following button:

 <md-button class="md-accent md-raised button-arquivo-margin"
                   ng-disabled="vm.controladorRequisicao.requisicaoSolicitada"
                   aria-label="Arquivo(s)">
            <div layout="row"
                 layout-align="center start"
                 flex>
                <input class="input-selecao"
                       im-file-change="vm.metodos.selecionarArquivos($event, arquivos)"
                       type="file"
                       multiple />
                <i class="icon-file s30"></i>
                <span class="title">Arquivo(s)</span>
            </div>
 </md-button>

where im-file-change="vm.metodos.selecionarArquivos($event, arquivos)" is only a directive that gets the input files from Event and binds with my model. After selecting the same files are displayed in a table as shown below: inserir a descrição da imagem aqui

However I am having a problem of poor usability of the system, in which people are moving or deleting the files before making the upload to API, so when trying to send the files causes a problem ... And did the checks the requisition does not get to be completed so only a Undefined of the requisition ...

I wonder if it is possible to somehow consist if files exist in the folder. So before sending I would check if the files exist in the folder and if they do not exist I could inform the user that the files were moved or deleted from the current folder.

1 answer

1

This is how I can solve my problem. When files are moved or deleted from the folder where they were selected, in Event.target.files the model’s selection input and bind with Angularjs, the size of the selected files is reset as shown in the image below: Arquivos após serem movidos ou deletados da pasta, ficando com seu tamanho zerado

So I created a simple method that will always consist the size of the files before sending them:

function _consistirArquivos(arquivos) {
        var verificadorArquivosIncosistentes = false;
        for (let i = 0; i < arquivos.length; i++) {
            var arquivo = arquivos[i];
            if (arquivo.size == 0) {
               verificadorArquivosIncosistentes  = true;
               break;                        
            }
        }
        return verificadorArquivosIncosistentes                            
};

Browser other questions tagged

You are not signed in. Login or sign up in order to post.