首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在未使用Refile上传图片的情况下阻止发送表单?

如何在未使用Refile上传图片的情况下阻止发送表单?
EN

Stack Overflow用户
提问于 2020-01-09 09:09:21
回答 1查看 13关注 0票数 0

我正在使用refile在我的应用程序中上传一些图像。

这是我的看法。

代码语言:javascript
复制
<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>

这是我的模型。

代码语言:javascript
复制
#talent.rb
  attachment :digital_full_length_1, type: :image

和我的配置:

代码语言:javascript
复制
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)

问题所在。有时,用户放入一些大文件,按下表单上的提交,请求就会中断(超时等)。

有没有办法避免在未使用refile上传文件时发送表单?

谢谢

EN

回答 1

Stack Overflow用户

发布于 2020-05-23 14:23:01

参考他们的documentation https://github.com/refile/refile#5-javascript-library的这一部分。这里有一个如何使用upload:startupload:success侦听器来实现这一点的示例。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59655898

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档