Something goes wrong with converting bytes
-
I'm trying to create a progressbar for downloading. I can catch the raw postback info: -----------------------------7d4204b3f043c Content-Disposition: form-data; name="__VIEWSTATE" dDwtMTI3OTMzNDM4NDs7Pp/0hcX8BMxmXMGOJJC27tgAEod8 -----------------------------7d4204b3f043c Content-Disposition: form-data; name="file"; filename="P:\logo.gif" Content-Type: image/gif GIF89an (lot of code for gif image) -----------------------------7d4204b3f043c-- Now i need to filter out the headers to be able to save it to a gif image(on disk). I tryed this by converting everything to string and filtering out the info. This worked, but for some reason my imagedata gets corrupted. Original: 00000000h: 47 49 46 38 39 61 14 01 6E 00 F7 00 00 F7 F7 F7 ; GIF89a..n.÷..÷÷÷ 00000010h: FF FB FF E7 E7 E7 D6 D3 D6 EF EB EF CE CB CE AD ; ÿûÿçççÖÓÖïëïÎËÎ 00000020h: 14 00 DE DB DE 18 45 AD 18 49 B5 10 34 84 10 3C ; ..ÞÛÞ.E.Iµ.4„.< After filter: 00000000h: 47 49 46 38 39 61 14 01 6E 00 77 00 00 77 77 77 ; GIF89a..n.w..www 00000010h: 7F 7B 7F 67 67 67 56 53 56 6F 6B 6F 4E 4B 4E 2D ; {gggVSVokoNKN- 00000020h: 14 00 5E 5B 5E 18 45 2D 18 49 35 10 34 04 10 3C ; ..^[^.E-.I5.4..< I'm probably doings something wrong in converting, or because i'm cutting in the string. Anybody know why this happens?
-
I'm trying to create a progressbar for downloading. I can catch the raw postback info: -----------------------------7d4204b3f043c Content-Disposition: form-data; name="__VIEWSTATE" dDwtMTI3OTMzNDM4NDs7Pp/0hcX8BMxmXMGOJJC27tgAEod8 -----------------------------7d4204b3f043c Content-Disposition: form-data; name="file"; filename="P:\logo.gif" Content-Type: image/gif GIF89an (lot of code for gif image) -----------------------------7d4204b3f043c-- Now i need to filter out the headers to be able to save it to a gif image(on disk). I tryed this by converting everything to string and filtering out the info. This worked, but for some reason my imagedata gets corrupted. Original: 00000000h: 47 49 46 38 39 61 14 01 6E 00 F7 00 00 F7 F7 F7 ; GIF89a..n.÷..÷÷÷ 00000010h: FF FB FF E7 E7 E7 D6 D3 D6 EF EB EF CE CB CE AD ; ÿûÿçççÖÓÖïëïÎËÎ 00000020h: 14 00 DE DB DE 18 45 AD 18 49 B5 10 34 84 10 3C ; ..ÞÛÞ.E.Iµ.4„.< After filter: 00000000h: 47 49 46 38 39 61 14 01 6E 00 77 00 00 77 77 77 ; GIF89a..n.w..www 00000010h: 7F 7B 7F 67 67 67 56 53 56 6F 6B 6F 4E 4B 4E 2D ; {gggVSVokoNKN- 00000020h: 14 00 5E 5B 5E 18 45 2D 18 49 35 10 34 04 10 3C ; ..^[^.E-.I5.4..< I'm probably doings something wrong in converting, or because i'm cutting in the string. Anybody know why this happens?
I'm thinking that it is the bytes --> string --> bytes convertion that currupts the info, so i was wondering if anyone knows a way in wich I can parse these headers out, just using byte[]. I think i would need a sort of byte[].Split(byte[] originalArray, byte[] splitOnFindingThis); Or is there a better way? I was also thinking, maybe i could split on \r\n, but that would also split up the file itself, so i don't think that is a good idea.
-
I'm trying to create a progressbar for downloading. I can catch the raw postback info: -----------------------------7d4204b3f043c Content-Disposition: form-data; name="__VIEWSTATE" dDwtMTI3OTMzNDM4NDs7Pp/0hcX8BMxmXMGOJJC27tgAEod8 -----------------------------7d4204b3f043c Content-Disposition: form-data; name="file"; filename="P:\logo.gif" Content-Type: image/gif GIF89an (lot of code for gif image) -----------------------------7d4204b3f043c-- Now i need to filter out the headers to be able to save it to a gif image(on disk). I tryed this by converting everything to string and filtering out the info. This worked, but for some reason my imagedata gets corrupted. Original: 00000000h: 47 49 46 38 39 61 14 01 6E 00 F7 00 00 F7 F7 F7 ; GIF89a..n.÷..÷÷÷ 00000010h: FF FB FF E7 E7 E7 D6 D3 D6 EF EB EF CE CB CE AD ; ÿûÿçççÖÓÖïëïÎËÎ 00000020h: 14 00 DE DB DE 18 45 AD 18 49 B5 10 34 84 10 3C ; ..ÞÛÞ.E.Iµ.4„.< After filter: 00000000h: 47 49 46 38 39 61 14 01 6E 00 77 00 00 77 77 77 ; GIF89a..n.w..www 00000010h: 7F 7B 7F 67 67 67 56 53 56 6F 6B 6F 4E 4B 4E 2D ; {gggVSVokoNKN- 00000020h: 14 00 5E 5B 5E 18 45 2D 18 49 35 10 34 04 10 3C ; ..^[^.E-.I5.4..< I'm probably doings something wrong in converting, or because i'm cutting in the string. Anybody know why this happens?
I also think the problem happens due to data conversion. Here is just my humble opinion: you can try again with the base64 encoding with help from the System.Convert class. When converting data from bytes to string, you can make use of the System.Convert.ToBase64String method, then you can filter out data. When converting data back to bytes, you can use the System.Convert.FromBase64String method. Hope that helps.