当前位置:网站首页>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.file
Non primitiveFile
file , ItsoriginFileObj
The attribute value is the originalFile
file , UseformData.append('file', file.originFileObj)
That is, it can be transferred to the background in the form of file streamajax
The head of the requestContent-Type
Need to bemultipart/form-data
Or other forms agreed by the background interface , But it must not beapplication/json
form
边栏推荐
- The right way to capture assertion failures in NUnit - C #
- Activiti常见操作数据表关系
- [gurobi] establishment of simple model
- 促进OKR落地的工作总结该如何写?
- Is l1-029 too fat (5 points)
- Devops Practice Guide - reading notes (long text alarm)
- SQL注入测试工具之Sqli-labs下载安装重置数据库报错解决办法之一(#0{main}thrown in D:\Software\phpstudy_pro\WWW\sqli-labs-……)
- Learn nuxt js
- Application of isnull in database query
- 【性能测试】一文读懂Jmeter
猜你喜欢
Sports [running 01] a programmer's half horse challenge: preparation before running + adjustment during running + recovery after running (experience sharing)
1. Kalman filter - the best linear filter
JVM中堆概念
Conversion of yolov5 XML dataset to VOC dataset
【性能测试】一文读懂Jmeter
Flask 常用组件
Chrome is set to pure black
论文学习——基于极值点特征的时间序列相似性查询方法
Comprendre la méthode de détection des valeurs aberrantes des données
L1-027 rental (20 points)
随机推荐
PHP session variable passed from form - PHP
C#实现一个万物皆可排序的队列
A method for detecting outliers of data
zabbix 5.0监控客户端
Fault analysis | MySQL: unique key constraint failure
L1-028 judging prime number (10 points)
一文了解數據异常值檢測方法
没有Kubernetes怎么玩Dapr?
根据数字显示中文汉字
L1-027 rental (20 points)
Leetcode 146. LRU cache
Add log file to slim frame - PHP
SQL statement view SQL Server 2005 version number
1. Getting started with QT
Project 1 household accounting software (goal + demand description + code explanation + basic fund and revenue and expenditure details record + realization of keyboard access)
2022 tower crane driver examination and tower crane driver examination questions and analysis
Call Baidu map to display the current position
Technology sharing | MySQL parallel DDL
Mouse over to change the transparency of web page image
Put a lantern on the website during the Lantern Festival