Skip to content Skip to sidebar Skip to footer

Nervgh Angular File Upload - How Do I Restrict The File Formats To Say Jpeg And Png?

I am upgrading an application that is using nv-file-select directive. I am unsure as to how to restrict the file formats supported for upload.

Solution 1:

You want to use the filters as described in the documentation.

Create the filter:

var uploader = $scope.uploader = new FileUploader({
    url: '/api/users/photo'
});

// FILTERS

uploader.filters.push({
    name: 'imageFilter',
    fn: function(item /*{File|FileLikeObject}*/, options) {
        vartype = '|' + item.type.slice(item.type.lastIndexOf('/') + 1) + '|';
        return'|jpg|png|jpeg|bmp|gif|'.indexOf(type) !== -1;
    }
});

Docs suggests entering it in the HTML, such as I have done below:

<inputtype="file" nv-file-select="" uploader="uploader" filters="imageFilter">

This code was used on his sample site that allows for image only uploads.

Solution 2:

I found the answer here:

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>

Post a Comment for "Nervgh Angular File Upload - How Do I Restrict The File Formats To Say Jpeg And Png?"