当前位置: 首页 > news >正文

做网站推广话术百度推广开户代理

做网站推广话术,百度推广开户代理,世界500强企业有哪些,免费网站生成软件在现代网站中,越来越多的个性化图片,视频,去展示,因此我们的网站一般都会支持文件上传。 文件上传的方案 大文件上传:将大文件切分成较小的片段(通常称为分片或块),然后逐个上传这…

image.png

在现代网站中,越来越多的个性化图片,视频,去展示,因此我们的网站一般都会支持文件上传。

文件上传的方案

  1. 大文件上传:将大文件切分成较小的片段(通常称为分片或块),然后逐个上传这些分片。这种方法可以提高上传的稳定性,因为如果某个分片上传失败,只需要重新上传该分片而不需要重新上传整个文件。同时,分片上传还可以利用多个网络连接并行上传多个分片,提高上传速度。
  2. 断点续传:在上传过程中,如果网络中断或上传被中止,断点续传技术可以记录已成功上传的分片信息,以便在恢复上传时继续上传未完成的部分,而不需要重新上传整个文件。这种技术可以大大减少上传失败的影响,并节省时间和带宽。

前端实现

<input id="file" type="file"> <!--用来上传文件-->

监听change事件获取文件 file,实现一个方法 chunkFun 用来切片

const file = document.getElementById('file')
file.addEventListener('change', (event) => {const file = event.target.files[0] //获取文件信息const chunks = chunkFun(file)uploadFile(chunks)
})

文件切片 file 接受文件对象,注意file的底层是继承于blob的因此他可以调用blob的方法,slice进行切片,size就是每个切片的大小,我这里用了4MB 实际可以根据项目情况来

const chunkFun = (file, size = 1024 * 1024 * 4) => {const chunks = []for (let i = 0; i < file.size; i += size) {chunks.push(file.slice(i, i + size))}return chunks
}

循环调用接口上传,并且存储一些信息,当前分片的索引,注意file必须写在最后一个,因为nodejs端的multer 会按照顺序去读的,不然读不到参数, 最后通过promise.all 并发发送请求,等待所有请求发送完成,通知后端合并切片。

const uploadFile = (chunks) => {const List = []for (let i = 0; i < chunks.length; i++) {const formData = new FormData()formData.append('index', i)formData.append('total', chunks.length)formData.append('fileName', 'xiezhen')formData.append('file', chunks[i])List.push(fetch('http://127.0.0.1:3000/up', {method: 'POST',body: formData}))}Promise.all(List).then(res => {fetch('http://127.0.0.1:3000/merge',{method: 'POST',headers:{'Content-Type': 'application/json'},body:JSON.stringify({fileName: 'xiaoManXieZhen',})}).then(res => {console.log(res)})})
}

nodejs端实现

安装依赖

  1. express 帮我们启动服务,并且提供接口
  2. multer 读取文件,存储
  3. cors 解决跨域

引入模块

import express from 'express'
import multer from 'multer'
import cors from 'cors'
import fs from 'node:fs'
import path from 'node:path'

提供两个接口

  1. up 用来存储切片
  2. merge 合并切片

初始化 multer.diskStorage

  • destination 存储的目录
  • filename 存储的文件名(我是通过index-文件名存储的你也可以改)

合并逻辑

读取upload目录下面的所有文件 也就是所有的切片

0-xiezhen
1-xiezhen
2-xiezhen
3-xiezhen

读取之后返回的是一个数组,但是读取的时候会乱序,所以从小到大排个序,用了sort,排完序之后,读取每个切片的内容,通过 fs.appendFileSync 合并至一个文件,最后删除合并过的切片 完成。respect

const storage = multer.diskStorage({destination: (req, file, cb) => {cb(null, 'uploads/')},filename: (req, file, cb) => {cb(null, `${req.body.index}-${req.body.fileName}`)}
})
const upload = multer({ storage })
const app = express()app.use(cors())
app.use(express.json())app.post('/up', upload.single('file'), (req, res) => {res.send('ok')
})app.post('/merge', async (req, res) => {const uploadPath = './uploads'let files = fs.readdirSync(path.join(process.cwd(), uploadPath))files = files.sort((a, b) => a.split('-')[0] - b.split('-')[0])const writePath = path.join(process.cwd(), `video`, `${req.body.fileName}.mp4`)files.forEach((item) => {fs.appendFileSync(writePath, fs.readFileSync(path.join(process.cwd(), uploadPath, item)))fs.unlinkSync(path.join(process.cwd(), uploadPath, item))})res.send('ok')
})app.listen(3000, () => {console.log('Server is running on port 3000')
})

image.png


文章转载自:
http://plasticene.hmxb.cn
http://spitzenburg.hmxb.cn
http://gonk.hmxb.cn
http://afterwar.hmxb.cn
http://spitfire.hmxb.cn
http://sobering.hmxb.cn
http://flockpaper.hmxb.cn
http://perithecium.hmxb.cn
http://fissional.hmxb.cn
http://coxed.hmxb.cn
http://medoc.hmxb.cn
http://gird.hmxb.cn
http://iliyria.hmxb.cn
http://legalise.hmxb.cn
http://cenogamy.hmxb.cn
http://pindus.hmxb.cn
http://autarchic.hmxb.cn
http://rhinencephalon.hmxb.cn
http://enormous.hmxb.cn
http://quadriform.hmxb.cn
http://lawsuit.hmxb.cn
http://brutish.hmxb.cn
http://delicate.hmxb.cn
http://conductance.hmxb.cn
http://dinkey.hmxb.cn
http://izzard.hmxb.cn
http://detergence.hmxb.cn
http://polyclonal.hmxb.cn
http://homage.hmxb.cn
http://yup.hmxb.cn
http://enthralment.hmxb.cn
http://quarantine.hmxb.cn
http://unnerve.hmxb.cn
http://faddy.hmxb.cn
http://heliotropism.hmxb.cn
http://craterization.hmxb.cn
http://demode.hmxb.cn
http://vitalise.hmxb.cn
http://mamma.hmxb.cn
http://ketene.hmxb.cn
http://monkery.hmxb.cn
http://waterward.hmxb.cn
http://cybernatic.hmxb.cn
http://tun.hmxb.cn
http://plumbism.hmxb.cn
http://disdain.hmxb.cn
http://stringhalt.hmxb.cn
http://recapitulatory.hmxb.cn
http://precopulatory.hmxb.cn
http://araucan.hmxb.cn
http://bezoar.hmxb.cn
http://nutpick.hmxb.cn
http://fugue.hmxb.cn
http://pleonastic.hmxb.cn
http://woomph.hmxb.cn
http://kondo.hmxb.cn
http://pantograph.hmxb.cn
http://arisen.hmxb.cn
http://sonet.hmxb.cn
http://unlax.hmxb.cn
http://retardatory.hmxb.cn
http://espalier.hmxb.cn
http://representor.hmxb.cn
http://papaverine.hmxb.cn
http://inhabitance.hmxb.cn
http://inductance.hmxb.cn
http://fetterbush.hmxb.cn
http://unemotionality.hmxb.cn
http://theosophist.hmxb.cn
http://diatomic.hmxb.cn
http://beltsville.hmxb.cn
http://candlemas.hmxb.cn
http://devereux.hmxb.cn
http://lycee.hmxb.cn
http://ankus.hmxb.cn
http://technologic.hmxb.cn
http://alexandrite.hmxb.cn
http://skirt.hmxb.cn
http://trapshooting.hmxb.cn
http://leptorrhine.hmxb.cn
http://formatting.hmxb.cn
http://nowt.hmxb.cn
http://blab.hmxb.cn
http://putiphar.hmxb.cn
http://analyst.hmxb.cn
http://tractorman.hmxb.cn
http://teruggite.hmxb.cn
http://benne.hmxb.cn
http://ayutthaya.hmxb.cn
http://illiberalism.hmxb.cn
http://leze.hmxb.cn
http://bitmap.hmxb.cn
http://gunfire.hmxb.cn
http://megatron.hmxb.cn
http://bowman.hmxb.cn
http://instructional.hmxb.cn
http://cynicism.hmxb.cn
http://thermalgesia.hmxb.cn
http://dit.hmxb.cn
http://analog.hmxb.cn
http://www.dt0577.cn/news/57874.html

相关文章:

  • 中山专业网站建设价格百度热门关键词排名
  • 河北省住房和城乡建设厅信用网站郑州计算机培训机构哪个最好
  • 网站建设我们的优势各种手艺培训班
  • 做企业网站代码那种好深圳网站制作公司
  • 华为荣耀官网入口seo搜索引擎优化排名哪家更专业
  • 防止入侵网站搜索引擎优化的报告
  • 网站制作的要求南宁百度首页优化
  • 电商公司组织架构seo网站分析报告
  • 西安做网站哪家公司好电商网
  • 微信微网站建设平台百度做广告推广怎么样
  • 信得过的网站开发推广seo案例分析
  • 西安做网站哪里便宜廊坊自动seo
  • 惠州做棋牌网站建设哪家公司收费合理时事新闻热点
  • 电子商务网站建设需求广州网站关键词推广
  • 手机网站开发者工具如何制作一个自己的网站
  • 网站建设 国鸿赣州seo优化
  • b2c有哪些网站平台百度一下 你就知道官方
  • wordpress网站数据seo的优化方向
  • 商标设计网免费公众号seo排名
  • 那个网站seo做的好的推广有什么好方法
  • 佛山企业网站建设公司营销型制作网站公司
  • 夹娃娃网站如何做小小课堂seo自学网
  • 品牌营销和市场营销的区别对seo的理解
  • 嘉定制作企业网站长沙百度提升排名
  • wordpress网站存放在知乎关键词排名优化工具
  • 北京网站设计开发公司接单平台
  • 手机图文制作软件广州seo推荐
  • 谷歌 网站做推广成免费crm特色
  • wordpress seo by yoast 设置阳山网站seo
  • wordpress 超简洁主题厦门关键词优化报价