【发布时间】:2016-11-28 01:41:55
【问题描述】:
在我的 rails 应用程序中,我将 jcrop 与 krajee 的 bootstrap-fileinput 一起使用。我将文件输入附加到我的表单,然后尝试在 img 元素上使用 jcrop。当我这样做时,图像预览会消失,并在其中放置一个损坏图像的图标。我不确定发生了什么。
var btnCust = '<button type="button" class="btn btn-default crop-image" title="Add picture tags">' +
'<i class="glyphicon glyphicon-tag"></i>' +
'</button>';
var previewCust = '<div class="file-preview-frame" id="{previewId}" data-fileindex="{fileindex}" data-template="{template}">' +
'<div class="kv-file-content">' +
'<img src="{data}" class="kv-preview-data file-preview-image cropbox" title="{caption}" alt="{caption}">' +
'</div>' +
'{footer}' +
'</div>';
$('#update-profile-photo-input').fileinput({
showClose: false,
browseLabel: '',
removeLabel: '',
showCaption: false,
defaultPreviewContent: "<img src='" + $('.profile-image').attr('src') + "' alt='Your Avatar' class='cropbox'>",
layoutTemplates: {main2: '{preview} ' + btnCust + ' {remove} {browse}', footer: ''},
previewTemplates: {image: previewCust}
});
$('.crop-image').on('click', function () {
$('.cropbox').Jcrop({
aspectRatio: 1,
setSelect: [0, 0, 175, 175],
onSelect: update,
onChange: update
})
});
function update(coords) {
$('#user_crop_x').val(coords.x);
$('#user_crop_y').val(coords.y);
$('#user_crop_w').val(coords.w);
return $('#user_crop_h').val(coords.h);
}
以下是文件输入创建的 html 的一部分。
html
<div class="kv-file-content">
<img src="blob:https%3A//my-app-werfds.c9.io/11176113-aab3-477c-bf1e-cf21a9c54cab" class="kv-preview-data file-preview-image cropbox" title="IMG_0315.JPG" alt="IMG_0315.JPG">
</div>
jcrop 遇到问题的预览图像有什么奇怪的地方吗?在我的控制台中,我收到一条错误消息,上面写着 GET blob:https%3A//my-app-werfds.c9.io/11176113-aab3-477c-bf1e-cf21a9c54cab 404 (not found)
我不确定还包括什么。我没有包括表格,因为我还没有尝试提交它。我只是在处理预览 img 时遇到 jcrop 问题。
这是jsfiddle (我很难实现上述所有代码,但这基本上是正在发生的事情)
【问题讨论】:
-
<img>的src好像是一个objectURL,可以创建一个jsfiddle jsfiddle.net 来演示吗? -
我会努力解决这个问题。我用控制台中出现的 404 错误更新了我的问题。
-
fileinput或jcrop是否撤销了 objectURL? -
对不起,我不明白,撤销是什么意思?
标签: javascript jquery ruby-on-rails image jcrop