fix 上传文件
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
const {spawn} = require('child_process');
|
||||
const { spawn } = require('child_process');
|
||||
const path = require('path');
|
||||
const {cwd} = require('process');
|
||||
const {readFile} = require("fs");
|
||||
const {post} = require("axios");
|
||||
const { cwd } = require('process');
|
||||
const { readFile, createReadStream } = require("fs");
|
||||
const { post } = require("axios");
|
||||
const https = require('https')
|
||||
|
||||
function seep(time) {
|
||||
return new Promise((res) => {
|
||||
@@ -13,18 +14,30 @@ function seep(time) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传图片至图床 (暂不可用)
|
||||
* 上传图片至图床
|
||||
* @param filePath 图片路径
|
||||
*/
|
||||
function uploadImg(filePath) {
|
||||
|
||||
readFile(filePath, function (err, data) {
|
||||
let formData = new FormData()
|
||||
formData.append('file', data)
|
||||
post('https://image.zmpt.cc/upload/localhost', formData).then((response, headers) => {
|
||||
console.info(response)
|
||||
async function uploadImg(filePath) {
|
||||
let data = createReadStream(filePath)
|
||||
console.log(data)
|
||||
// readFile(filePath, function (err, data) {
|
||||
try {
|
||||
let res = await post('https://image.zmpt.cc/upload/localhost', {
|
||||
file:data
|
||||
},{
|
||||
proxy: false,
|
||||
headers:{
|
||||
'Content-Type': 'multipart/form-data'
|
||||
}
|
||||
})
|
||||
})
|
||||
console.log(res)
|
||||
return res.data
|
||||
}catch(err){
|
||||
console.error(err)
|
||||
return err
|
||||
}
|
||||
|
||||
// })
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user