我有一个pdf文件的base64编码字符串,我可以使用Ruby
进行解码Base64.decode(the_string)
现在我想将它转换为HTTP::FormData::File
类型的对象,然后我可以使用http post将其上传到AWS S3。
如何执行此操作 没有 将文件写入磁盘并使用
重新读取HTTP::FormData::File.new("/path/to/file.pdf")
谢谢
答案 0 :(得分:1)
我猜你正在使用http-form_data gem。在这种情况下,您的答案就在HTTP::FormData::File docs的第一个示例中。后人:
使用StringIO
io = StringIO.new "foo bar baz" FormData::File.new io, :filename => "foobar.txt"
所以:
require "stringio"
require "base64"
io = StringIO.new(Base64.decode64(the_string))
file = HTTP::FormData::File.new(io, filename: "some_filename.txt")