19

I have recently found a file on the web, and I really need the original url to it, but it's encoded into Base64. It's an image.

The URL Starts with something like this: data:image/png;base64, and then there are loads of numbers and letters.

My question is, how can I decode this to its original form? e.g. instead of mwo1fw# to http://etc

Nick
  • 352
  • 2
  • 5
  • 20

10 Answers10

26

Use this web utility:

http://www.motobit.com/util/base64-decoder-encoder.asp

Set the output format to binary, then copy-paste the base64 data that follows data:image/png;base64,; your browser will download the file. Rename it to PNG and you're good to go.

  • 2
    You don't have the URL of the image -- it has NO URL. It's the raw PNG data that is encoded in Base64. –  Jun 19 '12 at 18:25
  • Ohhh!! _now_ I get it! Sorry, my bad! – Nick Jun 19 '12 at 18:30
  • Not sure why the guy didn't check your answer, but it worked for me. Thanks (althought that website is not the most intuitive – Juan Nov 10 '12 at 13:09
  • @Juan Thanks! Yes, it's not a very decent UX, but at least it works well :) –  Nov 10 '12 at 13:16
11

Another way to save the image is just to copy-paste data:image/png;base64, followed by the characters in your browser's url field..
and you'll see the image..
you could then save it to your computer..

iguider
  • 721
  • 1
  • 12
  • 25
  • 1
    Neat - however, note that this may depend on installed add-ons; I use Firefox with NoScript, and I get instead "*javascript: and data: URIs typed or pasted in the address bar are disabled to prevent social engineering attacks. Developers can enable them for testing purposes by toggling the "noscript.allowURLBarJS" preference.*" – sdaau Apr 03 '14 at 16:29
8

On Linux machines, there is this base64 utility you can use. Just two steps.

  • Save the base64 encoded text in a file (say image.base64). The base64 encoded text is everything after data:image/png;base64,
  • On a terminal type: base64 -d image.base64 > img.jpg

That's it. img.jpg is your image file. View it by double clicking the file from the file viewer.

CodeExpress
  • 2,202
  • 1
  • 20
  • 16
7

Try this online base64 decode/encode tool http://base64online.org/decode/

Just paste your base64 encoded image there and it will show you an image and download link for it.

Brig Ader
  • 799
  • 8
  • 7
  • That link seems to give `Error: invalid arguments` in `base64.js:171` in Error (Browser) Console on Firefox 28, and I cannot get it to show any conversion whatsoever. – sdaau Apr 03 '14 at 16:14
0

you can decode it here: http://base64decode.net/ and save the response as .png file

erica
  • 9
  • 1
0

If you have a Html5 compliant browser and Javascript enabled you can use Base 64 Online

Make sure to remove data:image/png;base64, from your encoded base64 image. Then paste the string into the text input area and click on "Decode > Download" and save the result as .png

0

How to export the Salesforce Quote PDF file and read convert it from Base64 back to PDF using Linux command Line

  1. Use Dataloader and export the QuoteDocument object with all fields and data

dataloader1

dataloader2

dataloader3   2. Use text editor, TextPad to open the csv file. Don’t use Notepad because it cannot handle the large size data and truncates it. 3. TextPad can handle the large data and respects any newlines characters, etc., when you open the file and also when you copy/paste the data. 4. Go to a specific row in the data and select and copy the cell field string that contains the PDF Base64 encoded data. Make sure you select it all the way to the end – but do not include subsequent fields after it.

textpad1

  1. Do not include subsequent fields after it.
  2. Select the string up to but do not include the quote " symbol.

textpad2

  1. Copy/paste the string into a new TextPad window.
  2. Save the new TextPad to a file, for example, document1.txt
  3. Copy the docuemnt1.txt file to your Linux computer (you could use Dropbox for this).
  4. Open a Linux command line terminal window
  5. Run the base64 decode command (base64 is part of the coreutils package), $ base64 --decode ~/Dropbox/linux_stuff/Document1.txt > ~/Dropbox/linux_stuff/decoded1.pdf
  6. This command will read in the Document1.txt file and output the decoded PDF file to decoded1.pdf.
  7. You can now open the decoded1.pdf file as an PDF file.
  8. You can rename the decoded1.pdf file to whatever you want, i.e., back to the original file name that was attached in the original Salesforce Quote object record.

linux_command_line

0

For the record, here is a quick and dirty Python 3 snippet.

import base64

def decode_base64_url(url):
    assert url.startswith('data:image/')
    assert ';base64,' in url
    schema, payload = url.split(',', 1)
    # Maybe parse the schema if you want to know the image's type
    # type = schema.split('/', 1)[-1].split(';', 1)[0]
    return base64.urlsafe_b64decode(payload)

You will probably want to run this from within a function which does open(..., 'wb') to write the payload to a binary file, or otherwise pass it to something which can cope with the raw image bytes. Perhaps see also Convert string in base64 to image and save on filesystem in Python

tripleee
  • 175,061
  • 34
  • 275
  • 318
0

You can use this website: https://ganixo.site

Submit your code and he will generate a link for you to download the decoded image.

Elletlar
  • 3,136
  • 7
  • 32
  • 38
0

Here's an elaboration on this excellent answer to make it fully-command line:

# optionally make a test image
echo "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAIAQMAAAD+wSzIAAAABlBMVEX///+/v7+jQ3Y5AAAADklEQVQI12P4AIX8EAgALgAD/aNpbtEAAAAASUVORK5CYII" > test.png

# chop off the leading MIME, decode it and redirect to a file
cat test.png | cut -c23- | base64 -d > decoded.png

# use whatever image-viewing application you want to see the result
firefox decoded.png

Or with NodeJS:

const fs = require("node:fs/promises");

(async () => {
  const b64 = await fs.readFile("test.png", "ascii");
  await fs.writeFile("decoded.png", b64.split(",")[1], "base64");
})();
ggorlen
  • 44,755
  • 7
  • 76
  • 106