如果文件大于1MB左右,则无法在新窗口中打开Blob [英] Opening blob in new window failing if file larger than 1MB or so

查看:145
本文介绍了如果文件大于1MB左右,则无法在新窗口中打开Blob的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个React项目,用户需要能够预览已上传的文档.我将文件存储在名为"upload"的变量的blob文件中,当用户单击预览按钮时,我使用以下代码在新标签中显示该文件:

I am building a react project where a user needs to be able to preview a document that has been uploaded. I have the file stored in a blob file in a variable called 'upload', and I use the following code to display it in a new tab when the user clicks on the preview button:

var newWIndow;
if (upload.includes("data:application/pdf"))
    newWIndow = "<iframe width='100%' height='100%' src='" + upload + "'></iframe>"
else
    newWIndow = "<img width='100%' src='" + upload + "'></img>";
var x = window.open();
x.document.open();
x.document.write(newWIndow);
x.document.close();

上传文件仅限于图片或pdf文件,并且效果很好,除非文件大小超过1MB.在这种情况下,它只会打开一个空白页面:

The uploads are limited to image or pdf files, and works great, except when the file size goes over 1MB. In that case, it simply opens a blank page:

整个blob文件太大,无法在此处发布,但是我认为了解一下它的外观可能会帮助某人发现我在做什么错,所以下面是一个代码段:

THe entire blob file is too large to post here, but I thought that giving an idea of what it looks like might help someone spot what I am doing wrong, so here is a snippet:

data:application/pdf; base64,JVBERi0xLjQNJeLjz9MNCjEgMCBvYmoNPDwvTWV0YWRhdGEgMiAwIFIvUGFnZXMgMyAwIFI

data:application/pdf;base64,JVBERi0xLjQNJeLjz9MNCjEgMCBvYmoNPDwvTWV0YWRhdGEgMiAwIFIvUGFnZXMgMyAwIFI

有人对我有什么建议吗?有没有更好的方法来打开上载的文档?有没有办法解决尺寸问题?任何建议将不胜感激.

Does anyone perhaps have any advice for me? Is there a better way to open the uploaded document? Is there a way to get around the size issue? Any advice would be greatly appreciated.

推荐答案

我错了,我没有使用blob对象,而是使用了二进制Base64对象.新问题及其解决方案已发布在

I was mistaken, I was not using a blob object but a binary Base64 one. The new question, as well as the solution, is posted in this post.

这篇关于如果文件大于1MB左右,则无法在新窗口中打开Blob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆