fix 上传文件

This commit is contained in:
theluyuan 2023-07-04 22:39:35 +08:00
parent 3011effebc
commit 55d45c0b1e
4 changed files with 45 additions and 30 deletions

View File

@ -10,11 +10,11 @@ const router = new Router()
router.get("/test", async (ctx) => { 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 = { ctx.body = {
code: 0, code: 0,
msg: "test", msg: "test",
data: '' data: res
} }
}) })

View File

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

View File

@ -83,7 +83,7 @@ import {router} from "../router/index.js";
import axios from "axios"; import axios from "axios";
function test() { function test() {
axios.get('/test').then(r => { axios.get('http://127.0.0.1:3050/test').then(r => {
}) })
} }

View File

@ -1,16 +1,8 @@
<template> <template>
<el-row> <div class="list">
<el-col <div class="item" v-for="i in 10">
v-for="(o, index) in 1"
:key="o"
:span="8"
:offset="index > 0 ? 2 : 0"
>
<el-card :body-style="{ padding: '0px' }"> <el-card :body-style="{ padding: '0px' }">
<img <img src="https://puui.qpic.cn/vcover_vt_pic/0/ww18u675tfmhas61669188848910/260" class="image" />
src="https://puui.qpic.cn/vcover_vt_pic/0/ww18u675tfmhas61669188848910/260"
class="image"
/>
<div style="padding: 14px"> <div style="padding: 14px">
<span>一念永恒</span> <span>一念永恒</span>
<div class="bottom"> <div class="bottom">
@ -19,14 +11,23 @@
</div> </div>
</div> </div>
</el-card> </el-card>
</el-col> </div>
</el-row>
</div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
</script> </script>
<style> <style lang="scss">
.list{
display: flex;
flex-wrap: wrap;
.item{
width: 200px;
margin: 5px;
}
}
.time { .time {
font-size: 12px; font-size: 12px;
color: #999; color: #999;
@ -49,4 +50,5 @@
width: 100%; width: 100%;
display: block; display: block;
} }
</style> </style>