express-chunk-upload
v1.1.2
Published
chunk upload with express
Downloads
6
Readme
express-chunk-upload
基于 express 的文件上传前后端工具套件(自动分片) | chunk upload with express, uploading made easy
使用 | usage
服务端 | server side
const express = require('express')
const getHandler = require('express-chunk-upload').default
const app = express()
app.use('/upload',getHandler({
uploadPath: __dirname+ '/uploads'
}))
浏览器端(webpack环境) | client side(webpack)
const Uploader = require('express-chunk-upload/dist/Uploader').default
let loader = new Uploader({url:'/upload'})
let item = loader.upload(input.files[0],{
onProgress: progress=>console.log(progress),
onError: error=>console.log(error),
onFinish: ({ fileName }) => console.log(fileName)
})
item.start().then(fileName=>console.log(fileName))
Next.JS
// pages/api/upload.js
import getHandler from 'express-chunk-upload'
import { join } from 'path'
import { fileURLToPath } from 'url'
export default getHandler({
uploadPath: join(
fileURLToPath(import.meta.url), '..', '..', '..', 'public', 'uploads')
})
export const config = {
api: {
bodyParser: {
sizeLimit: '10mb',
},
},
}