0

I have a file which contains base64 encoded image data: ~/dog/1.jpg

I put it there via SSH, and base 64 encoded the data so it would be safe to transfer in the terminal. Assume the base64 image data is not corrupted.

Now that I have the image data passed to the other server I need to decode the file contents and then overwrite the encoded file with the decoded file.

And I can't use the base64 command as it's not available on the remote server.

How can I base64 decode file contents and then overwrite the encoded file contents with the decoded contents, preferably using perl?

This is what I have now...

# Decode image data
poo=$(cat ~/dog/1.jpg | perl -MMIME::Base64 -ne 'printf "%s\n",decode_base64($_)'); 

# Write decoded data to file
echo $poo >| ~/dog/1.jpg

This overwrites the file but does not properly decode the image.

1 Answer 1

2
perl -MMIME::Base64 -i -0777ne 'print decode_base64($_)' ~/dog/1.jpg

Will avoid having to use any intermediary (be it a variable or a temp file) and stores the decoded file back into the original jpeg file.

1
  • exactly what i needed, ty Commented Apr 27, 2017 at 3:59

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.