简体   繁体   中英

How to store pdf and png to postgres DB?

I have tried to save pdf and png to postgres DB but not able to store the file in the db for future use.

i have created an api for storing the user info in those info i also wanted to store the pdf(resume) and png(profile pic) file of a user.

Below you can find my api using bytea d-type for pdf and png

const pool = require("../../DBConnection/DBConnection");

exports.uploadResume = async (req, res) => {
  try {
    const { firstName, lastName, email, profilePic } = req.body;
    console.log(firstName);
    const newUser = await pool.query(
      `INSERT INTO au_resume_uploader (first_name, last_name, email, resume, profilePic ) VALUES ($1, $2, $3, $4, $5) RETURNING *`,
      [firstName, lastName, email, resume, profilePic ]
    );
    res.json(newUser);
  } catch (err) {
    console.error(err.message);
  }
};

Looking for solution how to store the Any other alternative approach also be help full , tried using multer but not got any thing

You should upload your media files(images and pdfs) to a cloud service like AWS, google cloud etc. Or if you are working locally then to a media folder.

You can then store its path in your db.

Since You are using DB I am assuming you are using some sort of backend system So you may refer https://www.geeksforgeeks.org/file-uploading-in-react-js/

Typically we save path or file names to the database. And store the actual files in any file management system like one drive, google cloud...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM