login about faq

I have to send a zip file as attachment of a soap for a webserver using the MTOM technology.

Unfortunatly, the webserver doesn't accept base64 encoding and require the binary encoding; so i've used the FileAccess.ReadEntireFile method to get the binary data, and it works correctly because if i put the result in a txt file, then changes the extension to zip, the file can be open correctly.

But when i try to load the byte array in the MIME body, the methods lost some bytes and the file become corrupted.
I used SetBody, SetBodyFromBinary, SetBodyFromTextPlain( [...], "ansi" ) and even SetBodyFromFile( filepath ), and all of them makes the same joke. I tried by forcing the Charset to "ansi", the Content-Transfer-Encoding to "binary" and the Content-Type to "application/zip", something changes but is not enough.

Here a chunk of bytes in the MIME body

PKƒ“[GÈ]\ƒ:$20141201-20141210_20151027182804.XMLì]]s7²ý

instead of the original file

PK    ƒ“[GÈ]\ƒ\  : $   20141201-20141210_20151027182804.XMLì]Û’7’ý

It seems it lost NULL chars ( blanks spaces, but visible with Notepad++ ), and convert other characters...

How can i fix it? Wich is the best way to import files without dataloss?

asked Nov 05 '15 at 10:14

b_mat_ita's gravatar image

b_mat_ita
1112


I'd have to see a code snippet to see exactly what you are doing.

Data loss would occur whenever binary data (such as image data, or the binary compressed data of a zip archive) is treated as a string. A string is a sequence of characters where the byte representation follows a particular charset encoding (such as utf-8). Data loss happens whenever a program is told to interpret some chunk of binary non-character data as text. Inevitably what happens is that bytes are encountered that don't represent any character according to the charset specified (such as utf-8, utf-16, iso-8859-1, shift-JIS, or whatever..)

link

answered Nov 05 '15 at 10:55

chilkat's gravatar image

chilkat ♦♦
11.8k316358421

Thanks for the explanation, but which method i should use to avoid the data loss?

I agree that i have to treat it as binary, so i suppose i have to use the oMime.SetBodyFromBinary ( that sets automatically the encoding in "base64" and i have to turn it in "binary" ) but what about the parameter?
. if i pass the oFileAccess.ReadBinaryToEncode: it required an encoding between base64, qp, hex and url, i tried to pass "binary" value but it doesn't work ;
. if i pass the oFileAccess.ReadEntireFile: seems it uses the "utf-8" charset and lost some chars ( null, single and double quote, latin f with hooks ), and after changes the encoding to "binary", it return this:

PK[G]\\:$20141201-20141210_20151027182804.XML]?7CpG!k

. if i pass the oFileAccess.ReadEntireTextFile( filepath, "ansi" for keep the special chars ): after setting the encoding to "binary" and the content-type to "application/zip", this is the result :

PK [G]\\:$20141201-20141210_20151027182804.XML] 7 C pG!k

The method that return a better array of bytes is oMime.SetBody( oFileAccess.ReadEntireTextFile( filepath, "ansi" ) ) that returns this:

PKƒ“[GÈ]\ƒ\:$20141201-20141210_20151027182804.XMLì]Û’7’ýýƒCï–pGÁ!k¢

that keeps most special chars but not the null char.

link

answered Nov 05 '15 at 11:41

b_mat_ita's gravatar image

b_mat_ita
1112

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×29
×27
×22

Asked: Nov 05 '15 at 10:14

Seen: 686 times

Last updated: Nov 05 '15 at 11:41

powered by OSQA