简体   繁体   English

使用回形针和Rails从Amazon s3读取文件时出现无效的参数错误

[英]Invalid argument error when reading file from Amazon s3 using paperclip and rails

I'm having an issue reading an XML file after it is uploaded to amazon S3 via paperclip. 通过回形针将XML文件上传到Amazon S3后,读取XML文件时遇到问题。 I've checked and I can access the link using the URL given in the error, all access permissions appear to be fine. 我已经检查过,可以使用错误中给出的URL访问链接,所有访问权限似乎都很好。

Here's the code I'm using to open the file, which is where the error occurs; 这是我用来打开文件的代码,这是发生错误的地方;

f = File.open(@asset.file.url)

And the error is Errno::EINVAL - Invalid Argument 错误是Errno :: EINVAL-无效的参数

I've tried searching for a solution but most seem to be regarding images and not text files. 我曾尝试寻找解决方案,但大多数似乎与图像有关,而不是文本文件。

The S3 bucket is in Ireland region if that makes any difference. 如果有任何不同,S3存储桶位于爱尔兰地区。

You are not reading the file from your local disk you are reading the file from remote location. 您不是从本地磁盘读取文件,而是从远程位置读取文件。 Your code should be like this: 您的代码应如下所示:

require 'open-uri'
url_data = open(@asset.file.url).read()

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

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