当前位置:网站首页>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
边栏推荐
- Famous blackmail software stops operation and releases decryption keys. Most hospital IOT devices have security vulnerabilities | global network security hotspot on February 14
- Group programming ladder race - exercise set l2-002 linked list de duplication
- Leetcode(215)——数组中的第K个最大元素
- What sparks can applet container technology collide with IOT
- Collections in Scala
- Common components of flask
- Mouse over to change the transparency of web page image
- Leetcode 23. 合并K个升序链表
- Cannot click button when method is running - C #
- How to use C language code to realize the addition and subtraction of complex numbers and output structure
猜你喜欢

Project 1 household accounting software (goal + demand description + code explanation + basic fund and revenue and expenditure details record + realization of keyboard access)

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

The second session of the question swiping and punching activity -- solving the switching problem with recursion as the background (I)

Thesis learning -- time series similarity query method based on extreme point characteristics

Newh3c - network address translation (NAT)

zabbix监控系统自定义监控内容

Redis sentinel mechanism
![[Gurobi] 简单模型的建立](/img/3f/d637406bca3888b939bead40b24337.png)
[Gurobi] 简单模型的建立

1. Kalman filter - the best linear filter

Flask 常用组件
随机推荐
2022 gas examination registration and free gas examination questions
Azure ad domain service (II) configure azure file share disk sharing for machines in the domain service
[CV] Wu Enda machine learning course notes | Chapter 9
Newh3c - routing protocol (RIP, OSPF)
AcWing 244. Enigmatic cow (tree array + binary search)
es6总结
Collections in Scala
Show server status on Web page (on or off) - PHP
Leetcode 23. Merge K ascending linked lists
Using the rate package for data mining
Conversion of yolov5 XML dataset to VOC dataset
【Go基础】1 - Go Go Go
Oracle stored procedures and functions
Group programming ladder race - exercise set l2-002 linked list de duplication
Preliminary study on temporal database incluxdb 2.2
促进OKR落地的工作总结该如何写?
Google's official response: we have not given up tensorflow and will develop side by side with Jax in the future
广和通高性能4G/5G无线模组解决方案全面推动高效、低碳智能电网
[test de performance] lire jmeter
21个战略性目标实例,推动你的公司快速发展