2017-04-10 33 views
1

我遇到了iOS/Safari/Chrome的一个奇怪的限制。 用户可以选择一个图像,并将其filecontent粘贴到输入元素中。设置SRC值(iOS)后图像被截断

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

回答