Angular js fileupload позволяет только расширения изображения

Вы не можете перегружать операторов в JavaScript. Вы можете использовать функции, чтобы помочь

var plus = function(a, b) {
    return a + b;
};

var smaller = function(a, b) { 
    return a < b;
};

var operator = plus;
var total = operator(a, b);
operator = smaller;
if(operator(var1, var2)){ /*do something*/ }
0
задан OneLunch Man 15 February 2019 в 04:57
поделиться

2 ответа

Рассмотрел весь ваш код и прокомментировал.
Решение состоит в том, чтобы просто установить атрибут ввода файла на accept="image/*"

app.directive('uploadProfile', function () {
  return function (scope, element, attrs, $window) {
    var $uploadCrop;

    function readFile(input) {
      // if (input.files && input.files[0]) {
      // files are always avalible nowdays
      if (input.files[0]) {
        // You don't need the FileReader... (we will use object urls)
        // var reader = new FileReader();

        // reader.onload = function (e) {
          $('.cropper').addClass('ready')
          $window.alert('hi')
          $uploadCrop.croppie('bind', {
            url: URL.createObjectURL(input.files[0])
          }).then(function () {
            console.log("do nothing")
          });
        // }

        // reader.readAsDataURL(input.files[0]);
      }
      // All browswers support FileReader nowdays...
      // else {
      //   swal("Sorry - you're browser doesn't support the FileReader API");
      // }
    }

    // set file attribute's accept to "image/*" 
    // This will only allow users to only select images
    element.accept = 'image/*'

    $(element).on("change", function () {
      readFile(this)
    });

    $uploadCrop = $('.cropper').croppie({
      url: "/static/img/yahshua.jpg",
      viewport: {
        width: 170,
        height: 170,
        type: 'circle',
      },
      enableExif: true,
      enableZoom: true,
      enforceBoundary: false
    });

    // You are already doing this above
    // $(element).on('change', function () { readFile(this); });

    $('#cropImage').on('click', function (ev) {
      $uploadCrop.croppie('result', {
        type: 'base64', // I would encurage you to use blob & FormData instead
        size: 'viewport'
      }).then(function (resp) {
        scope.record = {}
        scope.record.cropped = resp
        scope.main.upload_profile(resp)
      });
    });
  };
})
.
0
ответ дан Endless 15 February 2019 в 04:57
поделиться

В ваш html-ввод типа «file» вы можете добавить атрибут «accept» для ограничения типа файла только изображениями: https://developer.mozilla.org/fr/docs/Web/HTML/Element/ Вход / файл

<input type="file"
       id="avatar" name="avatar"
       accept="image/png, image/jpeg">

0
ответ дан Kevin FONTAINE 15 February 2019 в 04:57
поделиться
Другие вопросы по тегам:

Похожие вопросы: