[英]Displaying content of an attached file as base64 in IE browser using JavaScript
I am calling a web service which returns a byte[] of an attachment. 我正在调用Web服务,该服务返回附件的byte []。 I then convert the byte[] to base64 string and return results to the client.
然后,我将byte []转换为base64字符串,并将结果返回给客户端。 i Then want to display this returned string in the browser (IE is necessary).
i然后要在浏览器中显示此返回的字符串(需要IE)。 i am getting file not found because i believe IE has URL length limit of a little over 2000. What are my options of displaying the attachment returned?
我找不到文件,因为我相信IE的URL长度限制超过2000。我显示退回附件的选项是什么? If there's no way to display it, how can i prompt user to save the attachment to a certain location using JavaScript?
如果无法显示它,如何提示用户使用JavaScript将附件保存到特定位置?
Here's what I have: 这是我所拥有的:
//Ascx page // Ascx页面
function retrieveAttachmentById() {
var DTO = { 'p_attachmentID': "123", 'p_itemId': "1" };
var url = "/_layouts/SharepointWebService/CustomService.asmx/GetAttachmentById";
$.ajax
({
type: "Post",
url: url,
data: JSON.stringify(DTO),
async: false,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function add(msg) {
var url = msg.d;
// display base64 content.
// window.location(url) doesn't work in IE when url is over 2047 characters.
},
error: function () { }
});
}
//CustomService.asmx //CustomService.asmx
[WebMethod]
public string GetAttachmentById(int p_attachmentID, int p_itemId)
{
byte[] fileBuffer = //Call service passing in p_attachmentID and p_itemId
var url64 = Convert.ToBase64String(fileBuffer); //Successful
return url64;
}
Any suggestions would be appreciated. 任何建议,将不胜感激。
You need to add the following entry in your web.config. 您需要在web.config中添加以下条目。 I believe thats the max value you can have for jsonSerialization
我相信这就是jsonSerialization可以拥有的最大值
<configuration>
...
...
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="2147483647"/>
</webServices>
</scripting>
</system.web.extensions>
<system.webServer>
...
...
</configuration>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.