Unable to pass the base 64 image string to apache velocity template for lamda mail - apache-velocity

Am keeping base64 encoded string
context.put("imagebase64str", base64str);
and using the following to get the image in template
Am printing in my console and generated template works if we save as html file and opens.. Image getting displayed perfectly..
When it invoked for lamda mail then image not getting loaded.
Kindly let me know what to be done for the fix.
Thanks

Related

convert online image uri into base64 with flutter

i read this post convert image to base64 with flutter but this is about converting image file to base64. How to convert online url to base64.
Right now i can think of one solution that is to store image in path and get that file path and convert it. thats how this post showing.
is there any other sort way to convert online image uri to base64?
Well to convert the image you need the image data otherwise there's nothing to convert. So the step for the most effecient would be.
Perform get request to the image url
Read all the bytes from the response body
Convert to base64
Save the base 64 string locally or use how you please.
You don't have to save it. Just keep in mind if the user closes the app or it stops at any point during this process you'll have to start it from the beginning because you're not saving the image to disk.

ActionDispatch::Http::UploadedFile to Base64

I'm currently working on a ruby on rails project. In the project I have a form with a input file type (An image) and I need to convert the image to base64 (The project connects to an external api, so the image needs to be in base64)
So far I have tried to do this Base64.encode64(target_params[:image].read)
but I get an empty string as result.
Just solve it using this code:
file =
target_params[:image].tempfile.open.read.force_encoding(Encoding::UTF_8)
Base64.encode64(file)

Encode Carrierwave attachment to base64 in Rails

I am using the Carrierwave gem to upload attachments to my model. I added elasticsearch with the mapper attachments plugin to allow for full text search of the attachments.
Carrierwave and elasticsearch work fine, but in order to get the full text search working I need to encode the attachment as base64.
I have followed this tutorial (http://rny.io/rails/elasticsearch/2013/08/05/full-text-search-for-attachments-with-rails-and-elasticsearch.html) but I assume there has been some changes to either Rails or Carrierwave as I can't get it to work. Specifically, when I am trying to encode the attachment as base64, I get the following Type error:
no implicit conversion of CarrierWave::SanitizedFile into String
The error is in the following line of the model:
File.open(Base64.encode64(File.read(document.file)))
If I replace the path with a url to an actual file it works fine.
I have searched SO and the only relevant answer I can find gives me the same error: Carrierwave encode file to base64 as process
I am a complete rails newbie and hopefully this is something that's obvious to everyone except me, but we're all beginners at first, right?
Thanks!
CarrierWave's read method returns the content of the file. So assuming Document is your model and file is your uploader attribute, this should work:
Base64.encode64(document.file.read)

Display response of Dropbox API thumbnail() in Rails app

I have successfully returned a thumbnail() request (using the Dropbox SDK) in my rails app, but I don't understand how to process the response. I would like to show the thumbnail on a webpage.
I also tried to save the response to a tmp file, but get a UndefinedConversionError ("\xFF" from ASCII-8BIT to UTF-8) error.
I'm actually doing exactly what you are asking for. What I did was to convert the returned bytes into a base64 string. In C# it's quite easy as there is a convert function to do that.
On the webpage you then have to set the src attribute of a img tag to
<img src="data: image/jpg;base64,PlaceBase64StringHere"...../>
There is a little overhead in the converted string, but it's very easy to handle and you use the power of the client browser to render the image.

From a controller action, how can I use binary data for an image to display the image in the view?

I have the binary data for an image in my controller action. I need to display the image in the view. How can I do this? I'm using Ruby 1.9.2 and Rails 3.0.1.
As coreyward above notes, it's not ideal to be doing this at all. But if you don't have an alternative (really, you probably do), you should look into data URIs.
It depends on what format your binary data is in, but the short version is that you will convert the data to a Base64-encoded string and then build a special URI that starts with data:, followed by the appropriate MIME type, and then the base64 string, and use that as the src attribute in a normal <img /> tag.

Resources