【发布时间】:2015-08-01 03:13:18
【问题描述】:
我正在努力完成this
尝试显示我要上传的图像的预览,但没有显示任何内容。我正在查看我的日志,当我尝试上传时,日志会吐出一些内容,主要是 Image Exists (0.2ms) 和 Image Load (0.3ms),并显示 SELECT 1 AS.... SQL 语法
这是我的 form.html.erb
<%= simple_form_for @photo, html: { multipart: true, id: 'bePhoto' } do |f| %>
<div class="row fileupload-buttonbar">
<div class="col-lg-7">
<!-- The fileinput-button span is used to style the file input field as button -->
<span class="btn btn-success fileinput-button">
<i class="glyphicon glyphicon-plus"></i>
<span>Add files...</span>
<input type="file" name="photos[]" multiple>
</span>
<button type="submit" class="btn btn-primary start">
<i class="glyphicon glyphicon-upload"></i>
<span>Start upload</span>
</button>
<button type="reset" class="btn btn-warning cancel">
<i class="glyphicon glyphicon-ban-circle"></i>
<span>Cancel upload</span>
</button>
<button type="button" class="btn btn-danger delete">
<i class="glyphicon glyphicon-trash"></i>
<span>Delete</span>
</button>
<input type="checkbox" class="toggle">
<!-- The global file processing state -->
<span class="fileupload-process"></span>
</div>
<!-- The global progress state -->
<div class="col-lg-5 fileupload-progress fade">
<!-- The global progress bar -->
<div class="progress progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100">
<div class="progress-bar progress-bar-success" style="width:0%;"></div>
</div>
<!-- The extended global progress state -->
<div class="progress-extended"> </div>
</div>
</div>
<!-- The table listing the files available for upload/download -->
<table role="presentation" class="table table-striped"><tbody class="files"></tbody></table>
<% end %>
然后我有这个 javascript
$(function () {
$('#bePhoto').fileupload();
$('#bePhoto').addClass('fileupload-processing');
$.ajax({
// Uncomment the following to send cross-domain cookies:
//xhrFields: {withCredentials: true},
url: $('#bePhoto').fileupload('option', 'url'),
dataType: 'json',
context: $('#beTripForm')[0]
}).always(function () {
$(this).removeClass('fileupload-processing');
}).done(function (result) {
$(this).fileupload('option', 'done')
.call(this, $.Event('done'), {result: result});
});
});
我也有这个
<script src="http://blueimp.github.io/JavaScript-Templates/js/tmpl.min.js"></script>
<script src="http://blueimp.github.io/JavaScript-Load-Image/js/load-image.all.min.js"></script>
<script src="http://blueimp.github.io/JavaScript-Canvas-to-Blob/js/canvas-to-blob.min.js"></script>
<script src="http://blueimp.github.io/Gallery/js/jquery.blueimp-gallery.min.js"></script>
还有这个:
//= require jquery-fileupload/basic
//= require jquery-fileupload/basic-plus
我几乎试图模仿示例演示,但不确定我是否正确地这样做。
【问题讨论】:
-
你的 Probloem @hellomello 是什么?服务器端或只是在上传前显示预览图像。
-
@bipashant 服务器端,我看不到预览
-
它是自动上传的,我认为它不应该上传,除非我也按下上传按钮
-
谈你的需求你只需要预览选择的文件就可以了?
标签: javascript jquery ruby-on-rails ruby-on-rails-4 jquery-file-upload