简体   繁体   English

获取S3 Object的下载流并将其传递给ruby中的另一个方法

[英]Get download stream of S3 Object and pass it to another method in ruby

Amazon S3 API for Ruby only streams objects when passing a block to the read method. 用于Ruby的Amazon S3 API仅在将块传递给read方法时流式传输对象。 I'm developing a driver for em-ftpd, and It needs an IOish object to stream the S3 data to the client. 我正在为em-ftpd开发一个驱动程序,它需要一个IOish对象来将S3数据流式传输到客户端。 If simply pass myS3Object.read, whole file is loaded into the memory, as stated by S3 API. 如果只是传递myS3Object.read,则整个文件被加载到内存中,如S3 API所述。 Is there any way of encapsulating that into something like a custom IO class, so I can pass the stream to em-ftpd? 有没有办法将其封装成类似自定义IO类的东西,所以我可以将流传递给em-ftpd?

Here is my code: 这是我的代码:

def get_file(path)
  #loading whole file into memory - not efficient
  yield bucket.objects[path].read
end

Here is the code inside em-ftpd that gets the result of my code, preferably as an IOish object, using a block to get its data chunks: 这是em-ftpd中的代码,它使用块来获取其数据块,从而获得我的代码的结果,最好是作为IOish对象:

# send a file to the client
def cmd_retr(param)
  send_unauthorised and return unless logged_in?
  send_param_required and return if param.nil?

  path = build_path(param)

  @driver.get_file(path) do |data|
    if data
      send_response "150 Data transfer starting #{data.size} bytes"
      send_outofband_data(data)
    else
      send_response "551 file not available"
    end
  end
end

Thank you. 谢谢。

事实证明我需要创建一个具有S3数据缓冲区和读取和eof方法的类。

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

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