Save / Recover files with PDF extension

1

To save files with PDF extension in the database do you need to do the conversion to base 64 ? Or would you have some other way to save this type and your recovery for viewing?

The code I have below, does the image conversion to base 64 , where image recovery is properly handled. When saving a PDF file it converts the same, but in the recovery of the file looks like this:

using(varstream=newMemoryStream()){clientesFotos.File.CopyTo(stream);System.IO.File.WriteAllBytes(path,stream.ToArray());clientesFotos.DocumentoString=Convert.ToBase64String(stream.ToArray());stream.Dispose();stream.Close();}

ReturnofConvertedFilesfromBase64

functionexibirDocumentos(img){//$("#overlay").show();
                $("#imagem").attr("src", "data:image/jpeg;base64," + document.getElementById(img).value);
            }
    
asked by anonymous 10.04.2018 / 20:14

2 answers

4

If you are saving as PDF, you can not display with content-type image / jpeg.

To display as image / jpeg, you first have to convert the PDF to jpeg.

    
10.04.2018 / 20:32
0

The best way to save files is to save to your hard drive.

But depending on the database, you have the option to save as varbinary(max) (FILESTREAM or BLOB), waiving the conversion, and can directly save the bytes in the database. When saving or retrieving, conversion to BASE64 is not required.

    
19.04.2018 / 19:44