base64 file to a varibale (like stringstream )

Hi,

I use the below function to get the contents of text files to a string variable so that I can use them to build MIME file for emailing.

Now I have a ZIPPed file converted to base64 file which I want to get it to a variable/buffer so that I can build my MIME file.

My question;

Is there a way similar to the below function or modify below so that it take base64 encoded file as an input return a string etc.

As I understand base64 encoded file is like a text file but when I use the below function the return string variable is empty.

Any help/ideas are much appreciated.


// function to convert file to a string
string FileToString(string filename)
{

ifstream fileToString(filename.c_str());
stringstream NewFileString;
NewFileString << fileToString.rdbuf();

return(NewFileString.str());

}

Regards,

Mathew
Hi Guys,

Any help for the above?
And how to handle a base64 encoded file?

Thanks

Mathew
The situation is taking the base64 and encoding in base 16 for most of the character systems that are used in email. But I am assuming that a base64 number is multiple bytes in length and is stored in a binary format which I can break down byte by byte and could be encoded to MIME fairly easily. If I wanted to insert text it, I would just count the bytes going by in the Mime encoding and stop the process print what I needed to print or what ever I was doing, like breaking up across multiple emails.

The base64 file has to be encode as a base16 on the disk. So storing the file is just printing the bytes of the file to which ever subsystem I needed to which I am Assuming MIME takes a unsigned char* of some form to encode its info. unsigned char is the equivalent to a single byte of information the base of the byte is irrelevant except to what ever needs to translate it on the other end after decoding.
Hi Azagaros,

Thank you for the reply. It looks like opening in binary mode doesnot help either. What is interesting is that with a simple code to open this base64 file & write to another fie after reading with "getline" works in text mode.

Also Wikipedia says base64 is a way to represent a binary file as text so that it can be set va text only smtp.

BTW, I use "zip" & "OpenSSL enc -base64" to generate base64 file of a zipped file. If I use a simple bash script to build a mime file to email, it works.

I thought I can consider the contents of base64 file as text so that I can read in text mode & use stringstream to hold the full file etc.

Any more ideas are much appreciated.

Mathew
Topic archived. No new replies allowed.