convert online image uri into base64 with flutter - dart

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.

Related

The right format for images in JSON

I'm working on a project using Swift. For it, I have to create a JSON file, which should also contain images. Now, I've tried to add Images to Xcode's Assets catalog and then create from them a Base-64 encoded string (I would like their format in a JSON to be a String). I use this code for one image to create the string:
let image = UIImage(named: "restaurant")
let imageData = UIImagePNGRepresentation(image!)
let strBase64 = imageData?.base64EncodedString(options: .endLineWithLineFeed)
When I encode this to JSON, it works normal. The problem is, in the future I won't have a JSON file inside of my project. It will be requested from the server, so when I manually add the Base-64 encoded string of my image to the JSON (first, I type it on the console, then, just copy it to JSON), my JSON file becomes terribly long (more than 2000 lines for just one image). After looking at the structure of different JSON files, used in tutorials, I've noticed that for images, the authors of those files use url strings. So, I wonder, whether it is the default way to add images to JSON and I shouldn't try to copy the whole Base-64 encoded string of my image? This is the first time I'm trying to add an image to a JSON, so I would appreciate any suggestion and advice.

Ruby on Rails - Transform base64 into image file without saving to use in multipart API call

I'm using RoR and I have a base 64 encoded image image_base64 = "data:image/jpeg;base64,/9j/4AAQSkZ...".
An API asks me to upload it as JPG file in a multipart/form-data parameter - e.g curl -X POST -F "images_file=#my_image.jpg"
I know how to turn the base 64 image into a file that would be saved somewhere (like in this other SO question), but I don't really want to be saving and deleting files, just create one on the fly. How can I do that?

How to send parameters with base64 image string using POST method in iOS?

I have parameters FirstName,LastName,Email & image ,Which need to send in the form of base64.I need appropriate code for it.
Base64 is used to convert binary data into text.
In your situation only Image needs to be encoded in that format, the rest should be text.
Convert UIImage to Base64 string in Objective-C and Swift

Base64 to video conversion

I am trying to convert a base64 string into a video file for use in a gem.
How do you take the base string and reformat it to what it was before it came through http.
Use Base64.decode and write directly the results to a file.
http://ruby-doc.org/stdlib-2.1.5/libdoc/base64/rdoc/Base64.html

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.

Resources