@vinvincent/uploadfile

1.0.9 • Public • Published

Introduction

UploadFile is a middleware for user to upload their file more easier

1. Install

if you use npm/cnpm

npm/cnpm install @vinvincent/uploadfile

if you use yarn

yarn add @vinvincent/uploadfile

2. Usage

At Client

when you want to upload one file

<!-- use a input dom element to choose files -->
<input id="file" type="file">
<script>
    let file = document.getElementById('file').files[0];
    let fromData = new FormData();
    fromData.append('file', file);
    axios.post('your-interface', fromData, {
        "content-Type": "multipart/form-data"
    })
</script>

when you want to upload more than one file

set the input dom element attribute multiple to be true

<!-- use a input dom element to choose files,set the attribute multiple to be true-->
<input id="file" type="file" multiple>
<script>
    let files = document.getElementById('file').files;
    let fromData
    if (files) {
        fromData = new FormData();
        for (file of files) {
            fromData.append('file', file);
        }
    }
    axios.post('your-interface', fromData, {
        "content-Type": "multipart/form-data"
    })
</script>

At Server

const uploadFile = require('@vinvincent/uploadFile')
//if you don't pass the parmas , the default path is `${process.cwd()} + './uploadfiles'`
app.use(uploadFile('your-uploadfile-path'))

Dependents (0)

Package Sidebar

Install

npm i @vinvincent/uploadfile

Weekly Downloads

2

Version

1.0.9

License

ISC

Unpacked Size

4.87 kB

Total Files

3

Last publish

Collaborators

  • vinvincent