当前位置:网站首页>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 .
边栏推荐
- 392. 判断子序列
- Unity shader learning (3) try to draw a circle
- 吃透Chisel语言.08.Chisel基础(五)——Wire、Reg和IO,以及如何理解Chisel生成硬件
- mac redis安装与使用,连接远程服务器 redis
- 程序员的焦虑
- go语言中的文件创建,写入,读取,删除(转)
- TestSuite and testrunner in unittest
- 吃透Chisel语言.09.Chisel项目构建、运行和测试(一)——用sbt构建Chisel项目并运行
- 華昊中天沖刺科創板:年虧2.8億擬募資15億 貝達藥業是股東
- 中邮科技冲刺科创板:年营收20.58亿 邮政集团是大股东
猜你喜欢

C# wpf 实现截屏框实时截屏功能

Dgraph: large scale dynamic graph dataset

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

MySQL之详解索引

2022g3 boiler water treatment examination question simulation examination question bank and simulation examination
![[FAQ] summary of common causes and solutions of Huawei account service error 907135701](/img/43/1a9786c89a5ab21d1fb8903cb7b77e.png)
[FAQ] summary of common causes and solutions of Huawei account service error 907135701

2022危险化学品经营单位主要负责人练习题及模拟考试

sharding key type not supported

Understand chisel language thoroughly 05. Chisel Foundation (II) -- combinational circuits and operators

Unittest框架中引入TestFixture
随机推荐
Mask wearing detection based on yolov1
FS4059C是5V输入升压充电12.6V1.2A给三节锂电池充电芯片 输入小电流不会拉死,温度60°建议1000-1100MA
Unittest框架之断言
小程序直播 + 电商,想做新零售电商就用它吧!
Mongodb commonly used 28 query statements (forward)
LifeCycle
Golang uses JSON unmarshal number to interface{} number to become float64 type (turn)
ARouter的使用
吃透Chisel语言.10.Chisel项目构建、运行和测试(二)——Chisel中生成Verilog代码&Chisel开发流程
IP lab monthly resumption · issue 5
JVM memory layout detailed, illustrated, well written!
markdown 语法之字体标红
[antd] how to set antd in form There is input in item Get input when gourp Value of each input of gourp
锐成芯微冲刺科创板:年营收3.67亿拟募资13亿 大唐电信是股东
Detailed explanation of Fisher information quantity detection countermeasure sample code
吃透Chisel语言.12.Chisel项目构建、运行和测试(四)——Chisel测试之ChiselTest
[antd step pit] antd form cooperates with input Form The height occupied by item is incorrect
Read excel table data
[R language data science]: cross validation and looking back
吃透Chisel语言.11.Chisel项目构建、运行和测试(三)——Chisel测试之ScalaTest