您可以通过使用临时文件(带有mp3扩展名)来解决这个问题,然后将其移动到可以由处理的位置
full_filename
正如预期的那样:
version :mp3 do
process :convert_to_mp3
def convert_to_mp3
temp_path = ... # generate good temp path, ending in '.mp3'
`ffmpeg -i #{ current_path.shellescape } -acodec libmp3lame -f mp3 #{ temp_path.shellescape }`
File.unlink(current_path)
FileUtils.mv(temp_path, current_path)
end
def full_filename(for_file)
super.chomp(File.extname(super)) + '.mp3'
end
end
生成temp_path的一些选项,供您测试和决定:
-
current_path.chomp(File.extname(current_path)) + '.mp3'
-
Tempfile.new([File.basename(current_path), '.mp3']).path
-
Rails.root.join('tmp', 'mp3', Dir::Tmpname.make_tmpname([original_filename,'.mp3'], nil))