Created
October 16, 2022 08:32
-
-
Save holyshared/0fba0f1fff7d42d7e529a7a02a8b8b93 to your computer and use it in GitHub Desktop.
form-data for multipart/mixed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fs from "fs"; | |
import path from "path"; | |
import FormData from 'form-data'; | |
const main = async () => { | |
const file = fs.readFileSync(path.resolve(__dirname, '../../scripts/example.txt.zip')); | |
const form = new FormData(); | |
form.append('data', file.toString('base64'), { | |
filename: 'example.txt.zip', | |
contentType: 'application/octet-stream; charset=utf-8', | |
header: { | |
'Content-Transfer-Encoding': 'binary' | |
} | |
}); | |
form.append('username', 'john', { | |
contentType: 'text/plain' | |
}); | |
form.append('password', 'pass', { | |
contentType: 'text/plain' | |
}); | |
form.submit({ | |
host: 'localhost', | |
port: '3000', | |
path: '/p', | |
headers: { | |
'Content-Type': 'multipart/mixed; boundary=' + form.getBoundary() | |
} | |
}, (err, res) => { | |
console.log(res.statusCode); | |
let c = "" | |
res.on('data', (chunk) => { | |
c += chunk | |
}) | |
res.on('end', () => { | |
console.log(c) | |
}) | |
}); | |
} | |
main().then(() => { | |
console.log('done'); | |
}).catch(err => { | |
console.log(err); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment