Rails Elastic Beanstalk - 没有这样的文件或目录

时间:2022-08-25 09:05:37

I have a rails app, deployed using Elastic Beanstalk. I want to use ffmpeg to get information about audio files, which are stored on S3, and am using the streamio-ffmpeg gem to make this a little easier.

我有一个使用Elastic Beanstalk部署的rails应用程序。我想使用ffmpeg获取有关存储在S3上的音频文件的信息,并使用streamio-ffmpeg gem来使这更容易一些。

I have installed ffmpeg on the EC2 instance, which is working fine when SSH-ing into the instance, and have everything working absolutely fine locally. I'm basically downloading the file from S3, and storing it in the /tmp folder, then calling on that through the streamio-ffmpeg gem.

我已经在EC2实例上安装了ffmpeg,这在SSH进入实例时工作正常,并且在本地工作一切正常。我基本上是从S3下载文件,并将其存储在/ tmp文件夹中,然后通过streamio-ffmpeg gem调用它。

s3 = AWS::S3.new(
:access_key_id => ENV["AWS_ACCESS_KEY_ID"],
:secret_access_key => ENV["AWS_SECRET_ACCESS_KEY"])
object = s3.buckets[ENV["AWS_S3_BUCKET"]].objects[CGI::unescape(self.url)]

tempname = Digest::MD5.hexdigest(DateTime.now.to_s) + "." + self.file_format
File.open(Rails.root.to_s + '/tmp/' + tempname, 'wb') do |f|
    f.write(object.read)
end

dl = Rails.root.to_s + '/tmp/' + tempname
audio = FFMPEG::Movie.new(dl)

The error occurs on that final line, when I get this error

当我收到此错误时,错误发生在最后一行

Errno::ENOENT (No such file or directory - ffmpeg -i /var/app/current/tmp/46951a3d16abb2e5fcf1da9e4cf8e0f3.flac)

Am I doing something stupid here? When I SSH into the instance, the file is where it should be, and when I run that line in the command line, it runs absolutely fine.

我在这里做些蠢事吗?当我SSH到实例时,该文件应该在哪里,当我在命令行中运行该行时,它运行绝对正常。

UPDATE I'm no expert on Linux, but running ls -l in the tmp directory gives me

更新我不是Linux的专家,但在tmp目录中运行ls -l给了我

-rw-r--r-- 1 webapp webapp 26445358 Apr  9 13:07 90da56d83822a0bf716b5dfaae27844b.wav

Are these permissions restrictive?

这些权限是否具有限制性?

Any help would be greatly appreciated

任何帮助将不胜感激

1 个解决方案

#1


0  

First, I would only construct the full path once and refer to it the same way in both places, so that there's no chance of them getting out of sync if you ever change how the path is put together. It should also make it easier to read.

首先,我只构造一次完整路径并在两个地方以相同的方式引用它,这样如果你改变了路径的组合方式,它们就不会失去同步。它也应该使它更容易阅读。

tempname = Digest::MD5.hexdigest(DateTime.now.to_s) + "." + self.file_format
temppath = Rails.root.join('tmp', tempname)
File.open(temppath, 'wb') do |f|
    f.write(object.read)
end

audio = FFMPEG::Movie.new(temppath)

If it still isn't found, the only thing I can think of is some sort of race condition, if it isn't quite visible to the OS right after it's been closed. Seems unlikely though.

如果仍然没有找到,我唯一能想到的就是某种竞争条件,如果操作系统在关闭后就不可见了。虽然看起来不太可能。

#1


0  

First, I would only construct the full path once and refer to it the same way in both places, so that there's no chance of them getting out of sync if you ever change how the path is put together. It should also make it easier to read.

首先,我只构造一次完整路径并在两个地方以相同的方式引用它,这样如果你改变了路径的组合方式,它们就不会失去同步。它也应该使它更容易阅读。

tempname = Digest::MD5.hexdigest(DateTime.now.to_s) + "." + self.file_format
temppath = Rails.root.join('tmp', tempname)
File.open(temppath, 'wb') do |f|
    f.write(object.read)
end

audio = FFMPEG::Movie.new(temppath)

If it still isn't found, the only thing I can think of is some sort of race condition, if it isn't quite visible to the OS right after it's been closed. Seems unlikely though.

如果仍然没有找到,我唯一能想到的就是某种竞争条件,如果操作系统在关闭后就不可见了。虽然看起来不太可能。