Я обучаю публикацию данных на сервере.
nodejs клиент:
import FormData from 'form-data'
import fs from 'fs'
function uploadModel(username: string, password: string) {
const form = new FormData()
const stream = fs.createReadStream(ZIP_FILE_NAME)
form.append('username', username)
form.append('password', password)
form.append('file', stream)
const formHeaders = form.getHeaders()
axios.post(host + 'upload_model', form, {
headers: {
...formHeaders,
},
}).then((response) => response).catch((error) => error)
}
nodejs конечная точка сервера:
import express from 'express'
import passport from 'passport'
import bcrypt from 'bcryptjs'
import { Strategy as LocalStrategy } from 'passport-local'
import { Accounts } from './db'
import cors from 'cors'
interface User {
username: string
}
const app = express()
app.use(require('cookie-parser')())
app.use(cors())
app.use(passport.initialize())
app.use(express.urlencoded())
app.use(express.json())
app.post('/upload_model', async function(req, res) {
try {
console.log('Try upload model. body', req.body) // body = {}
const { username, password } = req.body
console.log(username, password) // undefined undefined
res.end()
} catch (err) {
res.send(err)
}
})