国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

? ? ????? JS ???? multer (postgresql)? ???? ???? ????? ?? Nodejs Express REST API? ???? ??

multer (postgresql)? ???? ???? ????? ?? Nodejs Express REST API? ???? ??

Jan 25, 2025 am 12:32 AM

Node.js, Multer ? PostgreSQL? ???? ??? ??? ??? API ??

? ????? Node.js, Multer ? PostgreSQL? ???? ?? ? ?? ??? ??? ??? ???? ???? ???? ?? API? ???? ??? ?????. ??? ?? ?? ??? ???? ?????? ??? ?? ??? ? ????.

?? ??:

  • Node.js? PostgreSQL? ?? ? ???????.
  • Node.js ? PostgreSQL? ?? ??? ?????.
  • API ???? ?? Postman.

???? ??:

  1. ???? ???? ?? ? ???:

    mkdir imageUpload
    cd imageUpload
    npm init -y
  2. ??? ??:

    npm install express multer body-parser pg
  3. ???? ?? ???:

    <code>imageUpload/
    ├── index.js
    ├── images/
    ├── db/
    │   └── db.js
    └── routes/
        └── image_routes.js
    └── controllers/
        └── upload.js</code>
  4. PostgreSQL ?????? ? ??? ??? ??:

    CREATE DATABASE uploader;
    CREATE TABLE users (id SERIAL PRIMARY KEY, name VARCHAR(50) NOT NULL, icon VARCHAR NOT NULL);

?? ??:

  1. ?????? ??(db.js):

    const { Client } = require('pg');
    const client = new Client({
        user: 'postgres',
        host: 'localhost',
        database: 'uploader',
        password: 'YOUR_PASSWORD', // 請?zhí)鎿Q為您的數(shù)據(jù)庫密碼
        port: 5432,
    });
    client.connect().then(() => console.log("Connected to DB")).catch(err => console.error("數(shù)據(jù)庫連接失敗:", err.message));
    module.exports = client;
  2. ????? ??(index.js):

    const express = require('express');
    const bodyParser = require('body-parser');
    const app = express();
    const port = process.env.PORT || 4000;
    
    app.use(bodyParser.json());
    app.use(bodyParser.urlencoded({ extended: true }));
    app.use('/images', express.static('images')); // 設置靜態(tài)文件目錄
    
    require('./routes/image_routes')(app);
    
    app.listen(port, () => {
        console.log(`服務器運行在端口 ${port}`);
    });
  3. ?? ??(image_routes.js):

    const express = require('express');
    const uploadController = require('../controllers/upload');
    
    module.exports = (app) => {
        app.post('/upload/single', uploadController.upload.single('icon'), uploadController.uploadSingleImage);
        app.post('/upload/multiple', uploadController.upload.array('icon', 12), uploadController.uploadMultipleImage);
    };
  4. ??? ??? ????(upload.js):

    const multer = require('multer');
    const path = require('path');
    const client = require('../db/db');
    
    const storage = multer.diskStorage({
        destination: (req, file, cb) => cb(null, './images'),
        filename: (req, file, cb) => cb(null, `image-${Date.now()}${path.extname(file.originalname)}`),
    });
    
    const fileFilter = (req, file, cb) => {
        if (!file.originalname.match(/\.(jpg|jpeg|png)$/i)) {
            return cb(new Error('請上傳 JPG, JPEG 或 PNG 格式的圖片'), false);
        }
        cb(null, true);
    };
    
    exports.upload = multer({ storage, fileFilter });
    
    exports.uploadSingleImage = async (req, res) => {
        try {
            await client.query(`INSERT INTO users (name, icon) VALUES ('${req.body.name}', '${req.file.filename}')`);
            res.json({ statusCode: 200, status: true, message: '圖片上傳成功' });
        } catch (error) {
            console.error("圖片上傳失敗:", error);
            res.status(500).json({ statusCode: 500, status: false, message: '圖片上傳失敗' });
        }
    };
    
    exports.uploadMultipleImage = async (req, res) => {
        try {
            for (const file of req.files) {
                await client.query(`INSERT INTO users (name, icon) VALUES ('${req.body.name}', '${file.filename}')`);
            }
            res.json({ statusCode: 200, status: true, message: '所有圖片上傳成功' });
        } catch (error) {
            console.error("圖片上傳失敗:", error);
            res.status(500).json({ statusCode: 500, status: false, message: '圖片上傳失敗' });
        }
    };
    

???:

Postman? ???? ??? ??? ??? ?? ???? ???? /upload/single ?? /upload/multiple? POST ??? ????.

How to build NodeJS Express REST API to Upload Image using Multer(PostgreSQL)

? ??? YOUR_PASSWORD? PostgreSQL ?????? ????? ??? ??? ?? ?????. ? ??? ?? ???? ???? ?? ?? ??? ???????. ??? ?? ??? ?? ???????. ????? ??? ?? images? ???? ? ??? ???? ?? ?? ???.

? ??? ??? ?? ?? ? ??? ???? ???? ?? ???? ??? ???? ?????. YOUR_PASSWORD? ?? ?? ???? ?? ?? ???? ?????.

? ??? multer (postgresql)? ???? ???? ????? ?? Nodejs Express REST API? ???? ??? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? ????? ??
? ?? ??? ????? ???? ??? ??????, ???? ?????? ????. ? ???? ?? ???? ?? ??? ?? ????. ???? ??? ???? ???? ??? ?? admin@php.cn?? ?????.

? AI ??

Undresser.AI Undress

Undresser.AI Undress

???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover

AI Clothes Remover

???? ?? ???? ??? AI ?????.

Video Face Swap

Video Face Swap

??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

???

??? ??

???++7.3.1

???++7.3.1

???? ?? ?? ?? ???

SublimeText3 ??? ??

SublimeText3 ??? ??

??? ??, ???? ?? ????.

???? 13.0.1 ???

???? 13.0.1 ???

??? PHP ?? ?? ??

???? CS6

???? CS6

??? ? ?? ??

SublimeText3 Mac ??

SublimeText3 Mac ??

? ??? ?? ?? ?????(SublimeText3)

???

??? ??

?? ????
1783
16
Cakephp ????
1727
56
??? ????
1577
28
PHP ????
1442
31
???
Java vs. JavaScript : ??? ????? Java vs. JavaScript : ??? ????? Jun 20, 2025 am 12:27 AM

Java ? JavaScript? ?? ?? ????? ??? ?? ?? ?? ???? ????? ?????. Java? ??? ? ??? ?????? ??? ???? JavaScript? ?? ? ??? ??? ?????.

JavaScript ?? : ?? ?? JavaScript ?? : ?? ?? Jun 19, 2025 am 12:40 AM

JavaScriptCommentsareEnsentialformaining, ?? ? ???? 1) Single-LinecommentsERUSEDFORQUICKEXPLANATIONS.2) Multi-linecommentSexplaincleClexLogicOrprovidedEdeDDocumentation.3) inlineecommentsClarifySpecificPartSofcode.bestPractic

JS? ??? ???? ???? ??? JS? ??? ???? ???? ??? Jul 01, 2025 am 01:27 AM

JavaScript?? ??? ??? ?? ? ? ?? ??? ???????. 1. ?? ??? ??? ???? ?? ??? ????. ISO ?? ???? ???? ???? ???? ?? ????. 2. ?? ??? ?? ???? ??? ?? ???? ??? ? ??? ? ?? 0?? ????? ?? ??????. 3. ?? ?? ???? ???? ???? ?? ?????? ??? ? ????. 4. Luxon? ?? ???? ???? ?????? ???? ?? ????. ??? ?? ???? ????? ???? ??? ????? ?? ? ????.

? ? ???  ??? ?? ???? ??? ?????? ? ? ??? ??? ?? ???? ??? ?????? Jul 02, 2025 am 01:22 AM

TAGGSATTHEBOTTOMOFABLOGPOSTORWEBPAGESERVESPRACTICALPURSEO, USEREXPERIENCE, andDESIGN.1.ITHELPSWITHEOBYOWNSESPORENGENSTOESTOCESKESKERKESKERKERKERDER-RELEVANTTAGSWITHOUTHINGTEMAINCONTENT.2.ITIMPROVESEREXPERKEEPINGTOPONTEFOCUSOFOFOFOCUSOFOFOFOCUCUSONTHEATECLL

JavaScript vs. Java : ?????? ??? ? ?? JavaScript vs. Java : ?????? ??? ? ?? Jun 20, 2025 am 12:21 AM

JavaScriptIspreferredforwebDevelopment, whithjavaisbetterforlarge-scalebackendsystemsandandandoidapps.1) javascriptexcelsincreatinginteractivewebexperiences withitsdynatureanddommanipulation.2) javaoffersstrongtypingandobject-Orientededededededededededededededededdec

JavaScript : ???? ????? ??? ?? ?? JavaScript : ???? ????? ??? ?? ?? Jun 20, 2025 am 12:46 AM

javascriptassevenfundamentalDatatatypes : ??, ???, ??, unull, ??, ? symbol.1) ?? seAdouble-precisionformat, ??? forwidevaluerangesbutbecautiouswithfatingfointarithmetic.2) stringsareimmutable, useefficientconcatenationmethendsf

DOM?? ??? ?? ? ? ??? ?????? DOM?? ??? ?? ? ? ??? ?????? Jul 02, 2025 am 01:19 AM

??? ?? ? ??? DOM?? ??? ??? ? ?????. ??? ?? ????? ?? ??????, ??? ?? ???? ?? ????????. 1. ??? ??? addeventListener? usecapture ?? ??? true? ???? ?????. 2. ??? ??? ?? ???? usecapture? ???? ????? ?????. 3. ??? ??? ??? ??? ???? ? ??? ? ????. 4. ??? ?? ?? ?? ??? ?? ??? ??????? ??? ???? ?????. 5. ??? ?? ?? ?? ??? ?? ???? ?? ???? ? ??? ? ????. ? ? ??? ???? ???? JavaScript? ??? ??? ??? ????? ???? ???? ??? ??????.

Java? JavaScript? ???? ?????? Java? JavaScript? ???? ?????? Jun 17, 2025 am 09:17 AM

Java? JavaScript? ?? ????? ?????. 1. Java? ???? ???? ??? ? ??? ?????? ?????? ? ?? ???? ?????. 2. JavaScript? ?? ? ?? ?? ? ??? ?? ??? ???? ??? ? ?? ? ?? ?????.

See all articles