【问题标题】:How to get file path at file upload如何在文件上传时获取文件路径
【发布时间】:2016-01-14 05:18:47
【问题描述】:

我想使用 Cloudinary 的服务,我可以使用他们的server side code 上传文件。

但是我不明白如何获取提交文件的路径?

当用户选择具有普通文件输入字段的文件时,只有文件名与表单一起提交。

【问题讨论】:

    标签: html ruby-on-rails file-upload cloudinary


    【解决方案1】:

    我们建议使用我们与 CarrierWave 或 Attachinary 的集成。使用 CarrierWave,您将能够简单地使用以下内容:

    <%= form_for model do |f| %>
      ...
      <%= f.upload_field :image %>
    
    <% end %>
    

    所有其他事情都将在幕后为您完成,无需任何额外的编码,如我之前分享的示例项目所示。

    如果您仍然希望自己完成编码,那么您可以执行以下操作:

    <%= form_for model, html: {multipart: true} do |f| %>
      ...
      <%= upload_field_tag :image %>
    
    <% end %>
    

    然后在你的控制器中:

    def create
      Cloudinary::Uploader.upload params[:image]
      ...
    end
    

    【讨论】:

      猜你喜欢
      • 2017-02-20
      • 1970-01-01
      • 2016-03-13
      • 2018-12-11
      • 2017-05-31
      • 1970-01-01
      • 2011-08-14
      • 2022-12-07
      • 1970-01-01
      相关资源
      最近更新 更多