EdwardZZZ / articles

工作点滴记录
2 stars 0 forks source link

node upload #58

Closed EdwardZZZ closed 4 years ago

EdwardZZZ commented 5 years ago
const fs = require('fs');
const FormData = require('form-data');

const form = new FormData();
const filePath = './20170208092539_k2mLr.jpeg'; // path.resolve('')
const picStream = fs.createReadStream(filePath);

form.append('file', picStream, {
    knownLength: picStream.knownLength
})

form.submit('https://*.com/picUpload', (err, res) => {
    res.on('data', (data) => {
        console.log(data.toString());
    })
})