如何使用 Refile 阻止在图片未上传时发送的表单?



我使用重新文件在我的应用程序中上传一些图像。

这是我的看法。

<span class="file-upload">
<% if current_user.talent.digital_full_length_1.present? %>
<figure class="uploaded-img" style="background-image: url(  <%= 
asset_path ix_refile_image_url(current_user.talent, :digital_full_length_1, w: 300, h: 300, fit: 'fill', bg: '0fff') %>);">
<a href="" title="Remove" class="remove-item">Remove</a>
</figure>
<button type="button" class="btn-upload trigger-file-upload hidden"></button>
<% else %>
<figure class="uploaded-img hidden" style="background-image: url();">
<a href="" title="Remove" class="remove-item">Remove</a>
</figure>
<button type="button" class="btn-upload trigger-file-upload"></button>
<% end %>
<span class="upload-hint">Full Length</span>
<%= ff.attachment_field :digital_full_length_1, direct: true, presigned: true, class: "user_top_five" %>
</span>

这是我的模型。

#talent.rb
attachment :digital_full_length_1, type: :image

我的配置:

require "refile/s3"
aws = {
access_key_id: Rails.application.secrets.S3_ACCESS_KEY_ID,
secret_access_key: Rails.application.secrets.S3_ACCESS_KEY_SECRET,
region: Rails.application.secrets.S3_REGION,
bucket: Rails.application.secrets.S3_BUCKET
}
Refile.cache = Refile::S3.new(prefix: "cache", max_size: 15.megabytes, **aws)
Refile.store = Refile::S3.new(prefix: "store", **aws)

问题。有时用户放了一些大文件,在表单上按提交,请求被破坏(超时等(。

有没有办法避免在文件未上传时发送表格?

谢谢

https://github.com/refile/refile#5-javascript-library 参考其文档的这一部分。有一个示例说明如何对他们的upload:startupload:success听众做到这一点。

最新更新