Very simple question.. strangely can’t find any intuitive answers anywhere.
I got a HTML form with which allows users to upload an image.
When this form is submitted and goes to a Rails controller, how do I get the image? Suppose I want it in base64.
When I do:
image = params[“image”]. I just get a filename… but where is this file? is it in my server? How do I then convert this to base64? I guess the conversion is easy once I know where this file actually is in my server…
params['image']should be an instance ofRack::Multipart::UploadedFile, so you should be able to access the path on disk by doingparams['image'].path.P.S.: To save a character, most prefer to use symbols since most Rails hashes are
HashWithIndifferentAccessand can be accessed using a symbol or a key. Soparams[:image].path🙂