当前位置:网站首页>Wechat applet determines the file format of URL
Wechat applet determines the file format of URL
2022-06-29 09:17:00 【swag_ Special actor】
There are two ways of thinking
The first way of thinking
example : http://www.example.com:8888/group1/M00/00/85/rBITVV_Qh2mAdwB0cSE513.jpg
1. lookup URL the last one “.” The index of
2. Intercept all characters following this index ( Here is the suffix )
3. Get the suffix to match and judge whether it is in a certain format 
// Whether the file is a picture ( Method 1 )
var isImg = function (url) {
// Get the last . The location of
var index = url.lastIndexOf(".")
// To obtain the suffix
var ext = url.substring(index + 1) // wxs I won't support it substr
// Judge
return ['png', 'jpg', 'jpeg', 'bmp', 'gif', 'webp', 'psd', 'svg', 'tiff'].indexOf(ext.toLowerCase()) !== -1
}
The second way of thinking
1. take URL use “.” Split into arrays
2. Find the last item in the array ( The last item is the suffix )
3. Get the suffix to judge 
// Method 2
var isImg2 = function (url) {
// Suffix acquisition
let suffix = '';
// Get type results
let result = '';
// Division url Of “.”
const flieArr = url.split('.');
// Get the suffix of the last item in the split array
suffix = flieArr[flieArr.length - 1];
if (suffix != "") {
suffix = suffix.toLocaleLowerCase();
// Image format
const imglist = ['png', 'jpg', 'jpeg', 'bmp', 'gif']
// Match pictures
result = imglist.find(function (item) {
return item === suffix
})
return result
}
}
边栏推荐
- Yolo nano: a highly compact one look convolutional neural network for target detection
- Unity C # e-learning (12) -- protobuf generation protocol
- Instance error iopub data rate exceeded
- 手写 redux-thunk
- Pointnet的网络学习
- 使用GPU训练kernel切换
- Member inner class, static inner class, local inner class
- mongoDB 持久化
- 微信小程序判断url的文件格式
- ActiveMQ message component publish subscribe redelivery message redelivery
猜你喜欢

手写 redux-thunk

超融合架构和传统架构有什么区别?

图片格式-webp

Let's make a summary

记微信小程序setData动态修改字段名

Open3d farthest point sampling (FPS)

Unity C # e-learning (12) -- protobuf generation protocol

NPM common commands

July 2022 (advanced soft test) information system project manager certification enrollment Brochure

Detecting and counting tiny faces
随机推荐
Working for many years, recalling life -- three years in high school
记微信小程序setData动态修改字段名
verilog 等价操作符
H5 soft keyboard problem
Product manager certification enrollment brochure (NPDP) in July 2022
How is epoll encapsulated in golang?
Verilog 数据类型
General multiplier design, verilog code
Which securities company is good for opening a mobile account? Is it safe to open an account online?
Training kernel switching using GPU
Verilog data type
在 RedisTemplate 中使用 scan
Handwritten virtualdom
Handwriting Redux thunk
Uber前安全主管面临欺诈指控 曾隐瞒数据泄露事件
Verilog splicing operation symbol
一般乘法器设计,verilog code
SSD改進CFENet
微信小程序底部导航栏中间突出
Verilog 拼接操作符号