当前位置:网站首页>How to send pictures to the server in the form of file stream through the upload control of antd
How to send pictures to the server in the form of file stream through the upload control of antd
2022-07-04 08:21:00 【zwf193071】
Preface
This few days , Encountered a demand , It is required to send the picture to the server in the form of file stream , The interface document is as follows :
Request parameters picurl: 2020/9/10/jrg00002.jpg
file:jrg00002.jpg
Obviously ,file Parameter is File stream object , So how to upload pictures to the server
FormData
Files must be uploaded to the server in the form of file streams , There are many forms of file flow , such as Blob、FormData etc. , Here we chose FormData,ui Component selected antd, The core code is as follows
<template>
<a-upload name="file" list-type="picture-card" class="avatar-uploader" :multiple="true" :show-upload-list="false" :before-upload="beforeUpload" :file-list="fileList" @preview="handlePreview" @change="handleChange" >
<img v-if="item.value" :src="item.value" alt="avatar" />
<div v-else>
<a-icon :type="loading ? 'loading' : 'plus'" />
</div>
</a-upload>
</template>
<script> export default {
methods:{
handleChange(info) {
const file = info.file this.loading = true; const myDate = new Date() const year = myDate.getFullYear() const month = myDate.getMonth() + 1 const day = myDate.getDate(); const formData = new FormData(); formData.append('file', file.originFileObj); formData.append('picurl', `${
year}/${
month}/${
day}/${
file.name}`); formData.append('adcode', this.adcode) uploadPhotoImg(formData).then(res => {
console.log(res) }).finally(_=> {
this.loading = false }) } } } </script>
Pay attention to the following two points
info.fileNon primitiveFilefile , ItsoriginFileObjThe attribute value is the originalFilefile , UseformData.append('file', file.originFileObj)That is, it can be transferred to the background in the form of file streamajaxThe head of the requestContent-TypeNeed to bemultipart/form-dataOr other forms agreed by the background interface , But it must not beapplication/jsonform
边栏推荐
- Thesis learning -- time series similarity query method based on extreme point characteristics
- Call Baidu map to display the current position
- 2022 tower crane driver examination and tower crane driver examination questions and analysis
- PHP converts seconds to timestamps - PHP
- What does range mean in PHP
- Azure ad domain service (II) configure azure file share disk sharing for machines in the domain service
- AcWing 244. Enigmatic cow (tree array + binary search)
- L1-027 rental (20 points)
- Go h*ck yourself:online reconnaissance (online reconnaissance)
- ES6 summary
猜你喜欢
![[performance test] read JMeter](/img/c9/25a0df681c7ecb4a0a737259c882b3.png)
[performance test] read JMeter

墨者学院-phpMyAdmin后台文件包含分析溯源

Fault analysis | MySQL: unique key constraint failure

【Go基础】2 - Go基本语句

DM8 command line installation and database creation

SSRF vulnerability exploitation - attack redis

广和通高性能4G/5G无线模组解决方案全面推动高效、低碳智能电网

Oracle-存储过程与函数

Call Baidu map to display the current position

一文了解数据异常值检测方法
随机推荐
1、卡尔曼滤波-最佳的线性滤波器
Redis 哨兵机制
【Go基础】2 - Go基本语句
Sqli labs download, installation and reset of SQL injection test tool one of the solutions to the database error (# 0{main}throw in d:\software\phpstudy_pro\www\sqli labs-...)
Laravel page load problem connection reset - PHP
小程序容器技术与物联网 IoT 可以碰撞出什么样的火花
2022 examination questions for safety managers of metal and nonmetal mines (underground mines) and examination papers for safety managers of metal and nonmetal mines (underground mines)
Convert datetime string to datetime - C in the original time zone
FRP intranet penetration, reverse proxy
es6总结
R language uses cforest function in Party package to build random forest based on conditional inference trees, uses varimp function to check feature importance, and uses table function to calculate co
ctfshow web255 web 256 web257
Is l1-029 too fat (5 points)
L1-026 I love gplt (5 points)
L1-030 one gang one (15 points)
Moher college phpMyAdmin background file contains analysis traceability
运动【跑步 01】一个程序员的半马挑战:跑前准备+跑中调整+跑后恢复(经验分享)
1. Getting started with QT
Collections in Scala
Parallel shift does not provide any acceleration - C #