I need to uploading some PDF file into database and display it. I have found a way that posibly displaying the PDF file, but I had no idea how to save it into the database itself.
I tried some tutorials but nothing works. Right now, I have this code in my controller `
DB::table('pegawai')->insert([
'nama' => $request->nama,
'jabatan' => $request->jabatan,
'umur' => $request->umur,
'alamat' => $request->alamat,
'file' => $request->file
]);
`
The file always showing [BLOB -24]. Is there anything I could do to make the file get uploaded into the database? Thank You.
CodePudding user response:
Files stored in a database will typically be stored as BLOBS. A BLOB stands for Binary Large OBject. You can read more here.
Once your insert statement didn't return any errors, you should be able to check your database to see if the file content was really saved.
However, I would not advise you to store it in the database. They tend to be very large, and you would have slow speeds when trying to retrieve them.
It would be good to make use of other storage locations like the Storage folder of your Laravel project, or an online cloud storage service like AWS S3 or GCP Cloud Storage. Read more here.
CodePudding user response:
Why store the file with the database?
All modern browsers can read PDF Files !!
Upload the file to your project and store the path only in the database and when you want to view it just call the link and the file will appear.