【问题标题】:Images gets truncated after setting SRC Value (iOS)设置 SRC 值后图像被截断(iOS)
【发布时间】:2017-09-05 08:10:55
【问题描述】:

我遇到了来自 iOS/Safari/Chrome 的奇怪限制。 用户可以选择一张图片,并将其文件内容粘贴到输入元素中。

两者的长度不相等。这是 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/

【问题讨论】:

    标签: ios safari webkit


    【解决方案1】:

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

    Why is the default max length for an input 524288?

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

    【讨论】:

      猜你喜欢
      • 2018-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-23
      相关资源
      最近更新 更多