我有它返回字节数组的文件外部web服务(小,大20MB的文件的),它必须被转换成BASE64的字符串和包括在XML文件的Base64编码/解码的大文件
编码
代码我用转换的字节数组的base64是
Convert.ToBase64String(bytearray, 0, bytearray.Length, _
Base64FormattingOptions.InsertLineBreaks)
下面是实际的XML结构我使用LINQ到XML。
attachment = From Item In cpd _
Select New XElement("attachment", _
New XAttribute("id", Item.UniqueID), _
New XElement("attachmentDocumentInformation", _
New XElement("actor", New XAttribute("reference", Item.AttchRefId)), _
New XElement("documentDescription", _
New XElement("documentTitle", Item.Document), _
New XElement("documentType", "A"), _
New XElement("sequence", Item.Sequence))), _
New XElement("documentContent", _
New XAttribute("contentEncoding", "base64"), _
New XAttribute("id", "DocumentContent" + Item.UniqueID), _
New XAttribute("mimeType", Item.mimeType), _
Convert.ToBase64String(Item.Content, 0, Item.Content.Length, _
Base64FormattingOptions.InsertLineBreaks)))
解码
我用frombase64转换为接收到的XML文件
Convert.FromBase64String(documentContentinBase64)
时文件的体积更小尺寸它工作得很好,当它是一个大的文件转换返回“无这种接口支持“。
我有两个问题:
- 什么是大文件转换tobase64/frombase64的最佳方式?
- 在将字节数组转换为base64之后,构建带有base64文档的xml文件的最佳方式是什么?有没有人有一些代码?
感谢
'Convert.FromBase64String'没有这样的签名。你能确认你的代码吗? – Jay 2011-06-09 16:31:13
当你说“爆炸”时,你的意思是什么;有没有例外?如果是这样,请发布例外的内容。 – Jacob 2011-06-09 16:32:10
另外假设在这一点上,bContent是'documentContent'节点的值吗?为什么不序列化一个对象并让'XmlSerializer'为你做所有的工作? – Jay 2011-06-09 16:34:31