I have a .net XMS client to receive messages from the MQ. It can receive text files fine. But the problem starts when I try to receive .zip or png files. The problem is that the file saved is corrupted and always intreprets it as textmessage.
var filename = "test.png";
else if (message is IBytesMessage)
{
IBytesMessage bytesMessage = (IBytesMessage)message;
var messageLength = bytesMessage.ReadInt();
byte[] uploadPayload = new byte[messageLength];
bytesMessage.ReadBytes(uploadPayload, messageLength);
var filePath = _fileUtil.SaveBytesFile(fileName, uploadPayload);
return filePath;
}
if (message is ITextMessage)
{
var msg = (ITextMessage)message;
var result = msg.Text;
var plainTextBytes = Encoding.UTF8.GetBytes(result);
var filePath = _fileUtil.SaveBytesFile(fileName, plainTextBytes);
return filePath;
}
The msg.Text removes the characerters.
I opened the original png file in notepad++ and find the characters, for example below
O-humMkkVøgÆUf¯éÙô
I tried also copying the text and pasting the text in an new file corrupts the file. Am I missing something... gets translated to
O-humMkkV?g?Uf????
Anyway to read it with the missing characters
Send binary data (files) to MQ as type IBytesMessage.
You should use BodyLength to define the size of the byte[], not ReadInt.
Change the following line:
var messageLength = bytesMessage.ReadInt();
To:
var messageLength = (int)bytesMessage.BodyLength;
The ITextMessage logic works as expected when the content is text.