Preview failed H5 download word document, suggesting that this file can not be previewed, it may have been damaged, some may see a preview

H5 end mobile download files function, found that some word files can be opened online and some can not open, suggesting that "can not preview this file, it may corrupt";

But in the end download Pc is normally open, mobile end is not.

code show as below:

            byte[] array = result.DecryptContent;
            MemoryStream stream = new MemoryStream(array);
            StreamReader reader = new StreamReader(stream);
            var contentType = "application/msword";
            if (result.FileName.Contains(".docx"))
            {
                contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
            }
            return File(stream, contentType, result.FileName);

It can be seen contentType different types, can cause a preview, an error occurred while downloading, when he converted preview.

Hence the need for different types of word version is set contentType value can be, some people will pay attention docx file is created and then changed the name doc, it will also convert error. 

 

Published 209 original articles · won praise 370 · Views 19,540,000 +

Guess you like

Origin blog.csdn.net/lilinoscar/article/details/104819019