【发布时间】:2017-03-16 15:59:20
【问题描述】:
我有一个运行 aspx 的网络应用程序,它有点像旧版应用程序。在提交过程中,用户将支持文件(通常是转换为pdf的图片)上传到我们的sql server,在那里它们以二进制文件的形式存储,并且可以在审批期间的不同时间再次下载。
但是,我们现在刚刚开始遇到一个问题,即我们的用户无法在 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 的好坏版本,以便比较和分析损坏情况,这可能会有所帮助。