方案一:
- const axios = require('axios')
- const FormData = require('form-data')
- const fs = require('fs')
- const sdUpscaleOnAzure = async (req, res) => {
- const data = new FormData()
- data.append('image', fs.readFileSync('/temp/ai/sd/download/1.png'))
- let config = {
- headers: {
- ...data.getHeaders(),
- Accept: 'application/json',
- },
- method: 'post',
- }
- config.url = 'https://www.baidu.com'
- config.data = data
- console.log(config)
- axios({
- ...config,
- })
- .then(async (response) => {
- res.send({
- code: 200,
- data: {
- response: response.data,
- },
- message: '成功',
- })
- })
- .catch((err) => {
- res.send({
- code: 400,
- data: {
- err,
- },
- message: '失败2',
- })
- })
- }
复制代码 方案二:
- const data = new FormData()
- let tempData = config.data
- for (let key in tempData) {
- data.append(key, tempData[key])
- }
- config.data = data
- config.headers['Content-Type'] =
- 'multipart/form-data; boundary=' + data.getBoundary()
-
- axios({
- ...config,
- })
- .then((response) => {
- res.send({
- code: 200,
- data: {
- response: response.data,
- },
- message: '成功',
- })
- })
- .catch((err) => {
- res.send({
- code: 400,
- data: {
- err,
- },
- message: '失败',
- })
- })
复制代码
参考链接:
https://chat.xutongbao.top/
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |