当前位置:网站首页>Why should Base64 encoding be used for image transmission
Why should Base64 encoding be used for image transmission
2022-07-04 14:14:00 【Poets don't write poetry】
One 、 Background knowledge
In general use HTTP agreement , The transmission is character text or binary data , this 2 These scenarios cover almost all uses HTTP The scenario of the agreement .HTTP Provisions of the agreement , Use Content-Type The request header specifies the type of transmission message , This determines how the requestor organizes the data ( Coding and format ) And how the receiver parses the data .Content-Type Commonly used values are as follows :
1、application/x-www-form-urlencoded
The data sent in this way is url Top splicing , With key1=val1&key2=val2 The way to code ,key and val It's all going on URL transcoding , This is a form submission method , A form means that there are multiple values .
2、multipart/form-data
From the name , The data transmitted is multiple , And it is the format of the form , This way is actually a powerful way , It can meet almost all data transmission requirements , It's just not very direct to use , So we only use this method to submit documents , Because files can only be transferred in the form of byte streams , Take transferring a file as an example , Need one key, You can call it myFile, Then we need to define value Type and content , The type is fille, The content is the file byte stream . The service provider needs to first according to myFIle Take out the file , Then resolve according to the type .
3、application/json
In this way, the data is expressed in json Format organization , Put it in body Send in .
4、text/xml
In this way, the data is expressed in xml Format organization , Put it in body Send in , This format has gradually been json replace , because ,json The format is more concise .
Two 、 The actual use
When we transmit pictures , It may be front-end and back-end interaction , It could be 2 Back end interaction , The treatment is usually different , Because the front end is responsible for interface interaction , Sending HTTP Requests are usually rich Content-Type, So when the front end sends pictures , Will use multipart/form-data This way, , This is also the default rule of the front and back ends .
But in 2 When interacting with multiple backend , The default data format is application/json, So we need to transform the image data , Usually , We got the byte stream of the picture byte[ ] after , Not in json Medium direct transmission byte[ ], Because I'm worried about the transmission process , There are services that implicitly encode it and then decode it , This causes the byte stream to change , So we do it at the transmission source base64 code , because base64 The use of ASCII Coding is supported by all coding methods , Even if a service encodes and decodes it during transmission , It can also be restored as is . So use base64 Coding is a security policy , however base64 It will increase the volume by about one third .
in addition ,base64 It is also a format directly supported by browsers . The following can be shown directly .
边栏推荐
- 吃透Chisel语言.11.Chisel项目构建、运行和测试(三)——Chisel测试之ScalaTest
- go vendor 项目迁移到 mod 项目
- 30: Chapter 3: develop Passport Service: 13: develop [change / improve user information, interface]; (use * * * Bo class to accept parameters, and use parameter verification)
- xshell/bash/zsh 等终端鼠标滚轮乱码问题(转)
- C language programming topic reference
- [C question set] of VII
- IP lab monthly resumption · issue 5
- JVM 内存布局详解,图文并茂,写得太好了!
- 自主工业软件的创新与发展
- Deming Lee listed on Shenzhen Stock Exchange: the market value is 3.1 billion, which is the husband and wife of Li Hu and Tian Hua
猜你喜欢

Yingshi Ruida rushes to the scientific and Technological Innovation Board: the annual revenue is 450million and the proposed fund-raising is 979million

sharding key type not supported

2022 hoisting machinery command examination simulation 100 questions simulation examination platform operation

CVPR 2022 | 大幅减少零样本学习所需的人工标注,提出富含视觉信息的类别语义嵌入(源代码下载)...

Doctoral application | West Lake University Learning and reasoning system laboratory recruits postdoctoral / doctoral / research internship, etc

How to choose a technology stack for web applications in 2022

Qt如何实现打包,实现EXE分享

学内核之三:使用GDB跟踪内核调用链

Understand chisel language thoroughly 09. Chisel project construction, operation and testing (I) -- build and run chisel project with SBT

富文本编辑:wangEditor使用教程
随机推荐
FS4059C是5V输入升压充电12.6V1.2A给三节锂电池充电芯片 输入小电流不会拉死,温度60°建议1000-1100MA
英视睿达冲刺科创板:年营收4.5亿 拟募资9.79亿
安装Mysql
ARouter的使用
Unittest框架中引入TestFixture
使用默认路由作为指向Internet的路由
mac redis安装与使用,连接远程服务器 redis
程序员的焦虑
奇妙秘境 码蹄集
游戏出海,全球化运营
Unity Shader学习(三)试着绘制一个圆
Mask wearing detection based on yolov1
【Antd踩坑】Antd Form 配合Input.Group时出现Form.Item所占据的高度不对
国内酒店交易DDD应用与实践——代码篇
gorm 之数据插入(转)
Gorm read / write separation (rotation)
Product identification of intelligent retail cabinet based on paddlex
瑞吉外卖笔记
Understand chisel language thoroughly 11. Chisel project construction, operation and test (III) -- scalatest of chisel test
php 日志调试