我有一个运行aspx的web应用程序,它是一个传统应用程序。在提交期间,用户上传支持文档(通常是转换为pdf的图片)到我们的sql服务器,在那里它们被存储为二进制文件,并且可以在批准过程中的不同时间再次下载。从Adobe网站下载PDF文件无法打开,但可以在Edge中打开
但是,我们刚刚开始收到一个问题,现在我们的用户无法在Adobe中打开PDF并获得可怕的“文件已损坏,无法修复”。错误信息。他们仍然可以在MS Edge中打开,所以它们实际上并未损坏。我已经证实,在上传之前,pdf文件可以正常打开。
HttpPostedFile file = this.attachmentUploader.PostedFile;
if (file == null)
{
file = Session["postedFile"] as HttpPostedFile;
}
if (file != null)
{
var fileName = this.attachmentUploader.FileName;
fileName = fileName.Length >= 100 ? string.Concat(fileName.Substring(0, 50).Trim(), ".pdf") : fileName;
Attachment attachment = new Attachment()
{
FileName = fileName,
File = this.attachmentUploader.FileBytes
};
db.Attachments.Add(attachment);
db.SaveChanges();
}
这是下载代码
byte[] file = null;
// Code here to pull file from db
if (file != null)
{
Response.Buffer = true;
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "attachment;filename=support_doc.pdf");
Response.OutputStream.Write(file, 0, file.Length);
}
感谢任何帮助!
*“它们仍然可以在MS Edge中打开,所以它们实际上没有损坏。”* - 这是错误的。只是因为一个观众,可能是偶然的,正确地显示可能实际上是垃圾的东西,并不意味着数据不是垃圾。如果您共享PDF版本的好坏版本,以便对损坏进行比较和分析,可能会有所帮助。 – mkl