mime base64 decode not working

It appears to me that in some cases the mime base64 decode does not work.

I take the base64 text and paste it in here: http://codebeautify.org/base64-to-image-converter and it makes the image, but when I convert and write in my code the image is garbled.

looks like the problem is only on the simulator - on iOS and Android, it works fine.

strange.

and it works on apple mac simulator too… so just windows then.

How are you decoding the file?

How are you getting the file on to Windows?

How are you reading the file into Corona?

Rob

recreate like this.

  1. Rename the main.txt file attached to main.lua and make a project with it.

  2. run on apple mac, open sandbox - you will see a testcard jpg of a girl with a puppet.

  3. run on windows, open sandbox - you will see a very messed up jpg.

results should be the same on both, right?

On Windows, you need to use:

[lua]

io.open( path, “wb” )

[/lua]

Actually you should use “wb” everywhere.  It’s extra important on Windows. The “b” stands for “binary”. When you leave that off any byte that’s an ASCII 13 or ASCII 10 gets converted to the Windows/DOS CRLF  line endings. That is it on Windows text files are assumed to have a carriage return character (CR or ASCII 13 or sometimes referred to as \r) followed by a line feed character (LF or ASCII 13 or sometimes referred to as \n).  Unix based file systems like macOS, iOS and Android use a single line feed character for their end of line character. In theory replacing a 10 with a 10 is a no-harm operation, but to be safe, if you always write binary files with the “b” add on, it will always be binary safe and you only have to code it one way.

Bit of history, the old Mac OS7 (and maybe OS9) used a single carriage return (13) character. This made for a real challenge moving text files between OS7, Windows/DOS and Unix.

Rob

Brilliant - thx

looks like the problem is only on the simulator - on iOS and Android, it works fine.

strange.

and it works on apple mac simulator too… so just windows then.

How are you decoding the file?

How are you getting the file on to Windows?

How are you reading the file into Corona?

Rob

recreate like this.

  1. Rename the main.txt file attached to main.lua and make a project with it.

  2. run on apple mac, open sandbox - you will see a testcard jpg of a girl with a puppet.

  3. run on windows, open sandbox - you will see a very messed up jpg.

results should be the same on both, right?

On Windows, you need to use:

[lua]

io.open( path, “wb” )

[/lua]

Actually you should use “wb” everywhere.  It’s extra important on Windows. The “b” stands for “binary”. When you leave that off any byte that’s an ASCII 13 or ASCII 10 gets converted to the Windows/DOS CRLF  line endings. That is it on Windows text files are assumed to have a carriage return character (CR or ASCII 13 or sometimes referred to as \r) followed by a line feed character (LF or ASCII 13 or sometimes referred to as \n).  Unix based file systems like macOS, iOS and Android use a single line feed character for their end of line character. In theory replacing a 10 with a 10 is a no-harm operation, but to be safe, if you always write binary files with the “b” add on, it will always be binary safe and you only have to code it one way.

Bit of history, the old Mac OS7 (and maybe OS9) used a single carriage return (13) character. This made for a real challenge moving text files between OS7, Windows/DOS and Unix.

Rob

Brilliant - thx