简体   繁体   English

重命名回形针上传的文件

[英]Rename files uploaded by paperclip

How do I rename files uploaded by Paperclip? 如何重命名Paperclip上传的文件? I have uploaded file /public/system/attachments/15/original/abc.txt 我已上传文件/public/system/attachments/15/original/abc.txt

How do I rename abc.txt file into for example xyz.txt ? 如何将abc.txt文件重命名为例如xyz.txt? I know how to update file name attributes of an object, but how to make these changes on the file system? 我知道如何更新对象的文件名属性,但是如何在文件系统上进行这些更改?

You need to adapt the:url and :path options from has_attached_file 您需要调整has_attached_file中的:url和:path选项

In this great tutorial (thewebfellas.com) you'll find it all. 在这个很棒的教程 (thewebfellas.com)中,您将找到所有内容。 :) :)

edit: to just move on disk, after having completed the uploading, you can use FileUtils 编辑:只需在磁盘上移动,完成上传后,即可使用FileUtils

#!/usr/bin/env ruby

require 'fileutils'

FileUtils.mv('/your/old/file', '/your/new/file')

Oh and File::rename as well of course. 哦,当然还有File :: rename

#!/usr/bin/env ruby
File.rename("afile", "afile.bak")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM