设置SRC值(iOS)后图像被截断

时间:2017-04-10 10:14:49

标签: ios safari webkit

我遇到了iOS / Safari / Chrome的一个奇怪的限制。 用户可以选择一个图像,并将filecontent粘贴到输入元素中。

两者的长度不相等。这是iOS限制吗?

    L.users.importConfigurations = function(options) {
  var target = null;

  this._getInputFileElement = function() {
    var that = this;
    fileInput = $('<input type="file" accept="image/*" style="display:none;" capture="camera" />');
    fileInput.change(function() {
      that._handleFiles(fileInput);
    });
    return fileInput;
  };

  this.showFileSelectionDialog = function() {
    var fileInput = this._getInputFileElement();
    fileInput.click();
  };

  this._handleFiles = function(fileInput) {
    var files = fileInput[0].files;
    if (files && files.length) this._readFile(files[0]);
  };

  this._readFile = function(fileInfo) {
    var that = this;
    var reader = new FileReader();
    reader.onload = function(e) {
      that._uploadFile(e.target.result);
    };
    reader.readAsDataURL(fileInfo);
  };

  this._uploadFile = function(fileData) {
    var fbValue = $(options.target).closest('.fileboxframe').find(".fileboxvalue");
    if (fbValue && fbValue.length > 0) {
      alert("Length before: " + fileData.length.toString());
      fbValue.attr('src', fileData);
      alert("Length after (Should be same): " + fileData.length.toString());
      alert("Length after (Should be same): " + fbValue.attr("src").length.toString());
    }
  };

  this.showFileSelectionDialog();
};

https://jsfiddle.net/ChristophWeigert/81qu41L5/

1 个答案:

答案 0 :(得分:0)

我在这个主题中找到了答案:

Why is the default max length for an input 524288?

解决方案是使用textare而不是文本框。