From 55d45c0b1e1ca36d86e4c6d2a8688542d99b6a90 Mon Sep 17 00:00:00 2001 From: theluyuan <1162963624@qq.com> Date: Tue, 4 Jul 2023 22:39:35 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- router/index.js | 4 +-- util/utils.js | 39 ++++++++++++++++++--------- view/src/menu/leftMenu.vue | 2 +- view/src/page/subscribe/subscribe.vue | 30 +++++++++++---------- 4 files changed, 45 insertions(+), 30 deletions(-) diff --git a/router/index.js b/router/index.js index 4ef5efe..ed71688 100644 --- a/router/index.js +++ b/router/index.js @@ -10,11 +10,11 @@ const router = new Router() router.get("/test", async (ctx) => { - await utils.uploadImg('C:\\Users\\SummerTail\\Pictures\\Snipaste_2023-07-03_22-16-37.png') + let res = await utils.uploadImg('C:/Users/11629/Desktop/80032464_p0.jpg') ctx.body = { code: 0, msg: "test", - data: '' + data: res } }) diff --git a/util/utils.js b/util/utils.js index 8027ecf..90fa1ec 100644 --- a/util/utils.js +++ b/util/utils.js @@ -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 + } + + // }) } diff --git a/view/src/menu/leftMenu.vue b/view/src/menu/leftMenu.vue index e1d6b24..cdff852 100644 --- a/view/src/menu/leftMenu.vue +++ b/view/src/menu/leftMenu.vue @@ -83,7 +83,7 @@ import {router} from "../router/index.js"; import axios from "axios"; function test() { - axios.get('/test').then(r => { + axios.get('http://127.0.0.1:3050/test').then(r => { }) } diff --git a/view/src/page/subscribe/subscribe.vue b/view/src/page/subscribe/subscribe.vue index 297369f..574cd73 100644 --- a/view/src/page/subscribe/subscribe.vue +++ b/view/src/page/subscribe/subscribe.vue @@ -1,16 +1,8 @@ -