1

How do I convert uuencoded image to byte array?

My image is encoded like this:

begin 644 image.jpg
M_]C_X``02D9)1@`!``$`8`!@``#__@`?3$5!1"!496-H;F]L;V=I97,@26YC
********************** MANY LINES ***************************
MH`R]:TM=9TJ^TIK_`%32UO8#`;_1;V33=5M,E6\VQOH@9+:<8P)$!(!8=Z`,
M#P;X#T+P-!J"Z2=1O+_5[E+S6=<UO4)]6UW6+B-#%!)J&HW)\R46\1,<$2+'
/#&&=EC\V6:20`[.@#__9
`   
end

I would like to get byte array without need to save image on hdd first. After decoding I will save it directly into DB.

Hnus
  • 912
  • 2
  • 9
  • 24

1 Answers1

2

You have to remove the first and last line, many solutions here, RegEx are funny :o)

Then Convert.FromBase64String method should do the trick.

Edit

I was wrong since uuencode is not Base64.

You will have to find a third-party implementation. Here or here.

Or maybe use a native library like active template library.

Community
  • 1
  • 1
Orace
  • 7,822
  • 30
  • 45
  • `Convert.FromBase64String` looks like is exactly what Im looking for thanks. Should I remove new lines `\n` from data too? – Hnus Oct 10 '14 at 13:10
  • 2
    Yes you have to remove the new lines characters. "\r\n" or whatever, you should probably use Environment.NewLine property : http://msdn.microsoft.com/fr-fr/library/system.environment.newline%28v=vs.110%29.aspx – Orace Oct 10 '14 at 13:12
  • I still cant decode the data. I think its because I have data in Uuencode format and `Convert.FromBase64String` expects data in Base64. For example Base64 contains only alphanumeric characters plus `+` and `/` as you can see my data is not in that format. I think Uuencode can be converted to Base64 in some way and maybe then I can use `Convert.FromBase64String` method but still I dont know how or if its the right way. – Hnus Oct 13 '14 at 11:44