当前位置:网站首页>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 .
边栏推荐
- Interview disassembly: how to check the soaring usage of CPU after the system goes online?
- R语言ggplot2可视化:gganimate包创建动态折线图动画(gif)、使用transition_reveal函数在动画中沿给定维度逐步显示数据
- 30: Chapter 3: develop Passport Service: 13: develop [change / improve user information, interface]; (use * * * Bo class to accept parameters, and use parameter verification)
- gorm 之数据插入(转)
- 【Matlab】conv、filter、conv2、filter2和imfilter卷积函数总结
- 测试流程整理(3)
- Qt如何实现打包,实现EXE分享
- MySQL5免安装修改
- Hardware Basics - diode Basics
- Detailed explanation of Fisher information quantity detection countermeasure sample code
猜你喜欢
测试流程整理(2)
Understand chisel language thoroughly 09. Chisel project construction, operation and testing (I) -- build and run chisel project with SBT
使用默认路由作为指向Internet的路由
Unittest框架中引入TestFixture
基于YOLOv1的口罩佩戴检测
JVM memory layout detailed, illustrated, well written!
学内核之三:使用GDB跟踪内核调用链
CVPR 2022 | 大幅减少零样本学习所需的人工标注,提出富含视觉信息的类别语义嵌入(源代码下载)...
Test evaluation of software testing
392. 判断子序列
随机推荐
Install MySQL
qt 怎么检测鼠标在不在某个控件上
FS4059C是5V输入升压充电12.6V1.2A给三节锂电池充电芯片 输入小电流不会拉死,温度60°建议1000-1100MA
吃透Chisel语言.07.Chisel基础(四)——Bundle和Vec
php 日志调试
30: Chapter 3: develop Passport Service: 13: develop [change / improve user information, interface]; (use * * * Bo class to accept parameters, and use parameter verification)
国内酒店交易DDD应用与实践——代码篇
Programmer anxiety
游戏出海,全球化运营
Idea shortcut keys
LifeCycle
学习项目是自己找的,成长机会是自己创造的
Yingshi Ruida rushes to the scientific and Technological Innovation Board: the annual revenue is 450million and the proposed fund-raising is 979million
Understand chisel language thoroughly 12. Chisel project construction, operation and testing (IV) -- chisel test of chisel test
華昊中天沖刺科創板:年虧2.8億擬募資15億 貝達藥業是股東
吃透Chisel语言.09.Chisel项目构建、运行和测试(一)——用sbt构建Chisel项目并运行
Assertion of unittest framework
R语言dplyr包summarise_if函数计算dataframe数据中所有数值数据列的均值和中位数、基于条件进行数据汇总分析(Summarize all Numeric Variables)
Unittest框架之断言
Unity shader learning (3) try to draw a circle