流到Base64String - 内存不足异常 [英] Stream to Base64String - Out of memory exception
本文介绍了流到Base64String - 内存不足异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
帮助您解决此问题, 在源下面抛出System.OutOfMemory异常在线
返回Convert.ToBase64String(stream.ToArray());
private static string GetSPFileBinary(ClientContext ctx,string fileUrlPath)
{
ctx.RequestTimeout = Int32.MaxValue;
var spFile = ctx.Web.GetFileByServerRelativeUrl(fileUrlPath);
var spFileContent = spFile.OpenBinaryStream();
ctx.Load(spFile);
ctx.ExecuteQuery();
MemoryStream stream = new MemoryStream();
if(spFileContent!= null&& spFileContent.Value!= null)
{
spFileContent.Value.CopyTo(stream);
}
返回Convert.ToBase64String(stream.ToArray());
}
谢谢
解决方案
< p style ="margin:0px 0px 10.66px"> 检查是否有效:
返回Convert.ToBase64String(stream.GetBuffer(),stream.Length);
文件有多大? 跨度>
Help appreciated in resolving this issue, below source throws System.OutOfMemory exception at line
return Convert.ToBase64String(stream.ToArray());
private static string GetSPFileBinary(ClientContext ctx, string fileUrlPath) { ctx.RequestTimeout = Int32.MaxValue; var spFile = ctx.Web.GetFileByServerRelativeUrl(fileUrlPath); var spFileContent = spFile.OpenBinaryStream(); ctx.Load(spFile); ctx.ExecuteQuery(); MemoryStream stream = new MemoryStream(); if (spFileContent != null && spFileContent.Value != null) { spFileContent.Value.CopyTo(stream); } return Convert.ToBase64String(stream.ToArray()); }
Thanks
解决方案
Check if this works:
return Convert.ToBase64String( stream.GetBuffer(), stream.Length);
How large is the file?
这篇关于流到Base64String - 内存不足异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文