当前位置:网站首页>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
边栏推荐
- Fault analysis | MySQL: unique key constraint failure
- 一文了解数据异常值检测方法
- [go basics] 1 - go go
- Conversion of yolov5 XML dataset to VOC dataset
- L1-030 one gang one (15 points)
- ZABBIX 5.0 monitoring client
- es6总结
- Leetcode 23. Merge K ascending linked lists
- Famous blackmail software stops operation and releases decryption keys. Most hospital IOT devices have security vulnerabilities | global network security hotspot on February 14
- WordPress get_ Users() returns all users with comparison queries - PHP
猜你喜欢

Système de surveillance zabbix contenu de surveillance personnalisé

Wechat has new functions, and the test is started again

Comprendre la méthode de détection des valeurs aberrantes des données

Moher college phpMyAdmin background file contains analysis traceability

What does range mean in PHP

ZABBIX 5.0 monitoring client

DM8 tablespace backup and recovery

Easy to understand: understand the time series database incluxdb

谷歌官方回应:我们没有放弃TensorFlow,未来与JAX并肩发展

Newh3c - routing protocol (RIP, OSPF)
随机推荐
Sports [running 01] a programmer's half horse challenge: preparation before running + adjustment during running + recovery after running (experience sharing)
A method for detecting outliers of data
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
[test de performance] lire jmeter
[go basics] 1 - go go
DM8 command line installation and database creation
C # implements a queue in which everything can be sorted
snipaste 方便的截图软件,可以复制在屏幕上
C#实现一个万物皆可排序的队列
21个战略性目标实例,推动你的公司快速发展
Introduction to neural network (Part 2)
Cannot click button when method is running - C #
Moher College webmin unauthenticated remote code execution
SQL statement view SQL Server 2005 version number
PCIe knowledge points -010: where to get PCIe hot plug data
zabbix监控系统邮件报警配置
Group programming ladder race - exercise set l1-006 continuity factor
Leetcode 146. LRU cache
Thesis learning -- time series similarity query method based on extreme point characteristics
Unity-写入Word