How to convert base64 encoded string to HTTP::FormData::File in Ruby? -


i have base64 encoded string of pdf file, can decode using ruby

base64.decode(the_string) 

now want convert object of type http::formdata::file can upload using http post aws s3.

how do without writing out file disk , reading in using

http::formdata::file.new("/path/to/file.pdf") 

thank you

i'm guessing you're using http-form_data gem. in case, answer in first example in http::formdata::file docs. posterity:

usage stringio

io = stringio.new "foo bar baz" formdata::file.new io, :filename => "foobar.txt" 

and so:

require "stringio" require "base64"  io = stringio.new(base64.decode64(the_string)) file = http::formdata::file.new(io, filename: "some_filename.txt") 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -