简体   繁体   English

使用JavaScript在IE浏览器中将附加文件的内容显示为base64

[英]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.

相关问题 如何将base64字符串转换为Javascript中的文件对象,该文件对象应在IE浏览器中工作 - How to convert base64 string into file object in Javascript which should work in IE Browser JavaScript 从 Base64 下载文件字符串在 IE 中不起作用 - JavaScript Download file from Base64 string not working in IE 在IE 7中使用JavaScript将Base64 String保存为Excel .xls文件 - Save Base64 String as an Excel .xls file using JavaScript in IE 7 使用Javascript检索二进制文件内容,base64对其进行编码并使用Python对其进行反向解码 - Retrieving binary file content using Javascript, base64 encode it and reverse-decode it using Python 使用javascript将音频文件转换为base64 - converting audio file to base64 using javascript 使用路径将PDF文件转换为Java中的Base64字符串 - convert PDF file using path to Base64 String in Javascript 如何使用javascript将捕获的媒体文件转换为base64? - How to convert a captured media file into base64 using javascript? 如何使用javascript将base64转换为压缩文件? - how to convert base64 to a zipped file using javascript? 使用javascript将图像文件转换为base64字符串 - converting image file to base64 String using javascript 使用Javascript将base64图像保存到文件路径 - using Javascript to Save base64 image to File Path
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM