在确认弹出窗口中获取上传文件的文件名

时间:2014-04-11 14:51:25

标签: ruby-on-rails file-upload paperclip

我使用Paperclip上传文件。有没有办法获取要在确认消息中上传的文件的文件名?

这样的事情:

<%= f.submit confirm: "Are you sure you want to upload #{file.file_name}?" %>

如果不使用基于Javascript的上传器,这是否可行?

2 个答案:

答案 0 :(得分:0)

 //call the function and get the uploaded file name
    function GetFileNmae() {
      var oFReader = new FileReader();
      oFReader.readAsDataURL(document.getElementById("file_field").files[0]);
      oFReader.onload = function (oFREvent) {
        file_name = oFREvent.target.result;
        alert(file_name);
      };
    };

尝试以上代码

答案 1 :(得分:0)

我在this answer找到了答案。事实证明我需要添加onclick事件:

<%= f.submit onclick: "return confirm('Are you sure you want to upload ' + document.getElementById('file-field').value + '?')" %>