I read a pdf file and then store its raw content into database. Now i want to read that content from database and create a pdf so that user can download it.
For this i read the content and write it to file with .pdf extension. But the result in an empty pdf file.
I am doing this because i want to avoid saving files in disk.
I am using beego framework.
Any suggestions/help?
Here what i am doing
Reading from pdf file and writing it to database
_,header,_:=c.GetFile("attachment[]")
attachment:=header.Filename
c.SaveToFile("attachment[]","/tmp/"+attachment)
content,_:= ioutil.ReadFile("/tmp/"+attachment)
s := string(content)
then write this 's' to database
reading from database and writing to pdf file
err := o.Raw("SELECT attachment FROM table_name WHERE id=?",id).QueryRow(&att)
if err == nil {
fmt.Println(att)
}
var data []byte
data = []byte(att)
ioutil.WriteFile("/tmp/hello.pdf",data, 0666)