Home > Software design >  How to Convert Image URL to base64 without downloading the file
How to Convert Image URL to base64 without downloading the file

Time:10-26

How would I be able to convert an image from a URL to base64 without downloading a file?

Example: https://pbs.twimg.com/profile_images/1455185376876826625/s1AjSxph_400x400.jpg

I want to access this URL and convert the image to base64 without the need to download the image itself.

So far I can only do it by saving the file but is it possible to do it without downloading it?

CodePudding user response:

Short answer. No.

Long answer. To process the file in any way, like encoding it, the file must be read into some memory accessible by the processor that will act upon it.

So, if the encoding process is running in your laptop then you need to download the file contents into it, saving it into a file, or directly to the stream in memory for the encoding process.

But, if the encoding process is done by a server of yours, sitting somewhere in the cloud, then you might not consider the content transfer as a "download". Purely terminology, because anyway, your server will need to access and read the file.

CodePudding user response:

Base64 is just encoding of some content. In your case it is encoding of image file content. And you can't get content without downloading.

  • Related