红宝石使用open-URI从S3读取文件 [英] ruby reading files from S3 with open-URI

查看:81
本文介绍了红宝石使用open-URI从S3读取文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从S3读取文件时遇到一些问题.我希望能够远程加载ID3标签,但是使用open-URI不起作用,它给我以下错误:

I'm having some problems reading a file from S3. I want to be able to load the ID3 tags remotely, but using open-URI doesn't work, it gives me the following error:

ruby-1.8.7-p302 > c=TagLib2::File.new(open(URI.parse("http://recordtemple.com.s3.amazonaws.com/music/745/original/The%20Stranger.mp3?1292096514")))
TypeError: can't convert Tempfile into String
    from (irb):8:in `initialize'
    from (irb):8:in `new'
    from (irb):8

但是,如果我下载相同的文件并将其放在桌面上(即无需打开URI),它就可以正常工作.

However, if i download the same file and put it on my desktop (ie no need for open-URI), it works just fine.

c=TagLib2::File.new("/Users/momofwombie/Desktop/blah.mp3")

我还应该做些其他的事情来读取远程文件吗?

is there something else I should be doing to read a remote file?

更新:我刚刚找到了此链接,该链接可能会有所解释,但是肯定必须有某种方法可以做到这一点...

UPDATE: I just found this link, which may explain a little bit, but surely there must be some way to do this...

从远程服务器上的文件读取标头数据

推荐答案

可能想查看 AWS :: S3 ,一个用于Amazon的简单存储服务的Ruby库

Might want to check out AWS::S3, a Ruby Library for Amazon's Simple Storage Service

对文件进行AWS::S3:S3Object.find,然后使用about检索元数据

Do an AWS::S3:S3Object.find for the file and then an use about to retrieve the metadata

此解决方案假定您具有AWS凭证并有权访问包含相关文件的S3存储桶.

This solution assumes you have the AWS credentials and permission to access the S3 bucket that contains the files in question.

这篇关于红宝石使用open-URI从S3读取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆