之前发贴求助过上传的问题,@alucardpj 大侠推荐我用 nginx 的 upload module,几经周折之后,终于可以上传了
然而现在的问题是:
nginx 上传的文件都是 000000001 0000000002 这样子的,无法识别。想用 ruby 读出来然后重命名,但加断点后访问文件时说我没权限。
我开始以为是路径问题,于是把 nginx 配置里的upload_store /tmp/upload_tmp
改成了upload_store /home/terry/RubymineProjects/EIMV6/public/uploaded
,但是不行;
又把upload_store_access user:rw;
改成了upload_store_access user:rw group:rw all:rw;
,还是不行。
我的 Rails 里用了一个 carrierwave,这个不重要吧?nginx 配置的接管文件处理的代码长这样:
def self.save_uploaded_file(params)
z = self.new
z.name = params[:pdf_file_name]
z.save!
byebug
end
断点断住之后报这个错
(byebug) File.read params[:pdf_file_path]
*** Errno::EACCES Exception: Permission denied @ rb_sysopen - /home/terry/RubymineProjects/EIMV6/public/uploaded/0042681049
而且我试了下,直接从 irb 访问,也是报没权限:
terry@TerryUbuntu:~/RubymineProjects/EIMV6$ irb
2.3.0 :001 > File.read '/home/terry/RubymineProjects/EIMV6/public/uploaded/0000000001'
Errno::EACCES: Permission denied @ rb_sysopen - /home/terry/RubymineProjects/EIMV6/public/uploaded/0000000001
from (irb):1:in `read'
from (irb):1
from /home/terry/.rvm/rubies/ruby-2.3.0/bin/irb:11:in `<main>'
2.3.0 :002 > File.stat '/home/terry/RubymineProjects/EIMV6/public/uploaded/0000000001'
Errno::EACCES: Permission denied @ rb_file_s_stat - /home/terry/RubymineProjects/EIMV6/public/uploaded/0000000001
from (irb):2:in `stat'
from (irb):2
from /home/terry/.rvm/rubies/ruby-2.3.0/bin/irb:11:in `<main>'
2.3.0 :003 > File.file? '/home/terry/RubymineProjects/EIMV6/public/uploaded/0000000001'
=> false
请各位不吝赐教!谢谢!