简体   繁体   English

IBM XMS .Net 如何从 MQ 接收 png 和 jpg 等图像文件

[英]IBM XMS .Net how do I receive images files like png and jpg from the MQ

I have a .net XMS client to receive messages from the MQ.我有一个 .net XMS 客户端来接收来自 MQ 的消息。 It can receive text files fine.它可以很好地接收文本文件。 But the problem starts when I try to receive .zip or png files.但是当我尝试接收 .zip 或 png 文件时问题就开始了。 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. msg.Text删除字符
I opened the original png file in notepad++ and find the characters, for example below我在记事本++中打开原始png文件并找到字符,例如下面


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 .将二进制数据(文件)作为IBytesMessage类型发送到 MQ。

You should use BodyLength to define the size of the byte[], not ReadInt .您应该使用BodyLength来定义 byte[] 的大小,而不是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.当内容为文本时, ITextMessage逻辑按预期工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM