Today, many online companies give us unlimited space to store pictures in order to use them for different purpose, especially, to embed them in websites. Besides those free spaces, we can still upload pictures to our own space if we rent a place on a hosting server with unlimited space or a lot of space to store all kind of files including picture files.

 

To upload pictures, we need to create an upload page and the necessary functionalities to achieve this goal. First of all a route to an upload page need to be defined as below:

 

//route/admin.js
import express from 'express'
const adminRoute = express.Router()

import jobRoute from './admin/job.js'
adminRoute.use('/job',jobRoute)

import categoryRoute from './admin/category.js'
adminRoute.use('/category',categoryRoute)

import uploadRoute from './admin/upload.js'
adminRoute.use('/upload',uploadRoute)

export default adminRoute

 

// routes/admin/upload.js
import path from 'path'
import express from 'express'
const uploadRoute = express.Router()
import upload from '../../controller/admin/upload.js'

uploadRoute.get('/',async function(req,res){
    if(req.session.user){
        upload.getItem(req,res)
    }else{
        res.redirect('/admin/login')
    }
})

export default uploadRoute

 

// controller/admin/upload.js
import config from '../../config.js'

class Upload{
    constructor(){
        (async () => {
            this.config = await config()
        })()
    }

    async getItem(req,res){
        this.config.pageTitle = 'ទំព័រ Upload'
        this.config.route = '/admin/upload'

        res.render('base',{data:this.config})
    }
}

export default await new Upload()

 

GitHub: https://github.com/Sokhavuth/khmerweb-job

Heroku: https://khmerweb-job.herokuapp.com