7

I'm using this module, https://github.com/nervgh/angular-file-upload

I am using their simple example, http://nervgh.github.io/pages/angular-file-upload/examples/simple/

When you click "Choose file" button, it will open a window which allows us to pick a file that we want to upload. What I would like to happen is to only allow specific file extensions to be clicked. Is there a non-documented configuration which will do that?

For example, in the config, we only allowed .txt extensions, when I click "Choose file" button, it will open up a window and show all the files. However, files that doesn't have the extension .txt will be disabled.

I'm not doing this for security purposes. I am just following the design/instructions provided to me. :) I can always use mitm tools to intercept and allow other extensions to be uploaded.

1 Answer 1

16

You can simply achieve your goal by doing this

accept=".txt"

<input ui-jq="filestyle" type="file" nv-file-select="" accept=".txt" uploader="uploader" data-icon="false" data-classButton="btn btn-default" data-classInput="form-control inline v-middle input-s" multiple>

more information

Sign up to request clarification or add additional context in comments.

6 Comments

I also got it to work using this code uploader.filters.push({ name: 'customFilter', fn: function(item) { return /\/(txt)$/.test(item.type) } });
I'll try your suggestion too
WOW, my answer is only filtering and your answer is the answer I really like! Thank you so much!!!!! :D
what if i only want to accept extensions, png, gif and jpg, what will be the code? Will it be like this? accept=".txt|.png|.gif|.jpg"
@devwannabe If I want to disallow specific file types, what should I do?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.