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

高端响应式网站建设手机怎么建自己的网站

高端响应式网站建设,手机怎么建自己的网站,web美工培训,php中英双语农业公司网站源码先获取文件大小,然后将文件切片传输给前端,前端再按顺序组合所有切片。 vue /** 下载数据 */handleDownloadInstance(id, instanceName) {if (this.downloadProgressisVisible) {this.$showError(已经有文件在下载!)return}this.$showInfo(开始下载!)ge…

先获取文件大小,然后将文件切片传输给前端,前端再按顺序组合所有切片。

vue

    /** 下载数据 */handleDownloadInstance(id, instanceName) {if (this.downloadProgressisVisible) {this.$showError('已经有文件在下载!')return}this.$showInfo('开始下载!')getFileSize(id).then((response) => {this.downloadProgressisVisible = trueconst fileSize = response.sizethis.fileSize = fileSizethis.downloadPercentage = 0this.currentSize = 0console.log(response)// 计算分片数和每片大小const chunkSize = 10 * 1024 * 1024 // 10 MBconst totalChunks = Math.ceil(fileSize / chunkSize)// 保存所有分片的数据const allChunks = new Array(totalChunks)const self = thislet num = 0// 下载所有分片function downloadChunks() {for (let i = 0; i < totalChunks; i++) {const data = {start: i * chunkSize,end: (i + 1) * chunkSize - 1}downloadInstanceChunk(id, data).then(response => {return response}).then(chunkBlob => {// 保存分片数据allChunks[i] = chunkBlobnum += 1// console.log('下载完成', i)// 检查是否所有分片都下载完成if (num === totalChunks) {mergeChunks()self.$showSuccess('下载成功!')self.downloadProgressisVisible = false}self.downloadPercentage = Math.floor((num) / totalChunks * 100)self.currentSize = num * chunkSize}).catch(error => {console.error('Error:', error)self.downloadProgressisVisible = falseself.$showError('下载文件失败:' + error.data.message)})}}// 合并所有分片function mergeChunks() {// 创建一个 Blob 对象,包含所有分片数据const mergedBlob = new Blob(allChunks, { type: 'application/zip' })// 创建下载链接并模拟点击const downloadLink = document.createElement('a')downloadLink.href = URL.createObjectURL(mergedBlob)const fileName = `${instanceName}.zip`downloadLink.download = fileNamedownloadLink.click()}// 调用下载分片函数downloadChunks()}).catch(err => {console.log(err)this.$showError('下载文件失败:' + err.data.message)this.downloadProgressisVisible = false})},

go

func (handler *Handler) getFileSize(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {instanceID, err := request.RetrieveNumericRouteVariableValue(r, "id")if err != nil {return &httperror.HandlerError{StatusCode: http.StatusBadRequest, Message: "Invalid instance identifier route variable", Err: err}}instance, err := handler.DataStore.Instance().Instance(uint(instanceID))if err == bolterrors.ErrObjectNotFound {return &httperror.HandlerError{StatusCode: http.StatusNotFound, Message: "Unable to find a instance with the specified identifier inside the database", Err: err}} else if err != nil {return &httperror.HandlerError{StatusCode: http.StatusInternalServerError, Message: "Unable to find a instance with the specified identifier inside the database", Err: err}}// timeStr := instance.ReportTime.Format("2006-01-02 15:04:05")// timeStr = strings.Replace(timeStr, ":", "-", -1)// timeStr = strings.Replace(timeStr, " ", "-", -1)dirPath := instance.TempPathzipPath := instance.InstanceName + ".zip"zipPath = "/home/1.zip"dirPath = "/home/if !utils.DirExists(dirPath) {return &httperror.HandlerError{StatusCode: http.StatusNotFound, Message: "文件不存在", Err: fmt.Errorf("文件不存在")}}_, err = os.Stat(zipPath)if err != nil {err = utils.ZipDir(dirPath, zipPath, []string{".pcap"})if err != nil {return &httperror.HandlerError{StatusCode: http.StatusInternalServerError, Message: "压缩文件失败", Err: fmt.Errorf("压缩文件失败")}}}fileInfo, err := os.Stat(zipPath)if err != nil {return &httperror.HandlerError{StatusCode: http.StatusInternalServerError, Message: "os.Stat 失败", Err: err}}return response.JSON(w, map[string]int64{"size": fileInfo.Size(),})
}func (handler *Handler) downloadInstanceChunk(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {instanceID, err := request.RetrieveNumericRouteVariableValue(r, "id")if err != nil {return &httperror.HandlerError{StatusCode: http.StatusBadRequest, Message: "Invalid instance identifier route variable", Err: err}}start, err := request.RetrieveNumericRouteVariableValue(r, "start")if err != nil {return &httperror.HandlerError{StatusCode: http.StatusBadRequest, Message: "Invalid instance identifier route variable", Err: err}}end, err := request.RetrieveNumericRouteVariableValue(r, "end")if err != nil {return &httperror.HandlerError{StatusCode: http.StatusBadRequest, Message: "Invalid instance identifier route variable", Err: err}}instance, err := handler.DataStore.Instance().Instance(uint(instanceID))if err == bolterrors.ErrObjectNotFound {return &httperror.HandlerError{StatusCode: http.StatusNotFound, Message: "Unable to find a instance with the specified identifier inside the database", Err: err}} else if err != nil {return &httperror.HandlerError{StatusCode: http.StatusInternalServerError, Message: "Unable to find a instance with the specified identifier inside the database", Err: err}}// timeStr := instance.ReportTime.Format("2006-01-02 15:04:05")// timeStr = strings.Replace(timeStr, ":", "-", -1)// timeStr = strings.Replace(timeStr, " ", "-", -1)dirPath := instance.TempPathzipPath := instance.InstanceName + ".zip"zipPath = "/home/1.zip"dirPath = "/home/test"if !utils.DirExists(dirPath) {return &httperror.HandlerError{StatusCode: http.StatusNotFound, Message: "文件不存在", Err: fmt.Errorf("文件不存在")}}// err = utils.ZipDir(dirPath, zipPath, []string{".pcap"})if err != nil {return &httperror.HandlerError{StatusCode: http.StatusInternalServerError, Message: "压缩文件失败", Err: fmt.Errorf("压缩文件失败")}}fileInfo, err := os.Stat(zipPath)if err != nil {return &httperror.HandlerError{StatusCode: http.StatusInternalServerError, Message: "os.Stat 失败", Err: err}}// 计算最后一片的范围if end == 0 || int64(end) > fileInfo.Size() {end = int(fileInfo.Size()) - 1}zipFile, err := os.Open(zipPath)if err != nil {return &httperror.HandlerError{StatusCode: http.StatusInternalServerError, Message: "文件无法打开", Err: fmt.Errorf("文件无法打开")}}defer zipFile.Close()w.Header().Set("Content-Type", "application/zip")// w.Header().Set("Content-Type", "application/octet-stream")// w.Header().Set("Content-Length", strconv.FormatInt(fileInfo.Size(), 10))// 设置响应头部,指定传输的范围w.Header().Set("Content-Range", "bytes "+strconv.FormatInt(int64(start), 10)+"-"+strconv.FormatInt(int64(end), 10))w.WriteHeader(http.StatusPartialContent)// 将部分内容传输到客户端_, err = zipFile.Seek(int64(start), 0)if err != nil {return &httperror.HandlerError{StatusCode: http.StatusInternalServerError, Message: "Unable to seek to the specified position", Err: err}}io.CopyN(w, zipFile, int64(end)-int64(start)+1)return response.Empty(w)
}

http://www.dtcms.com/wzjs/217700.html

相关文章:

  • 网站关键字优化价格seo推广怎么入门
  • 公司简介怎么写吸引人seo百度快速排名
  • 网站开发vue深圳推广服务
  • 成都网站建设优化扬州seo优化
  • 淮安市建设厅网站企业培训课程种类
  • 专业做电脑系统下载网站好昆明seo博客
  • 公司网站制作知乎seo软件定制
  • 国家建设局网站首页关键词词库
  • 深圳罗湖做网站58下载百度极速版
  • 网络平台运营模式企业网站seo方案
  • 烟台市福山区住房和建设局网站河北百度推广
  • 做网站为什么可以自学seo自然搜索优化排名
  • 关于php动态网站开发的书籍app推广方式有哪些
  • 做外汇网站卖判刑多少年网络seo推广培训
  • 郑州seo规则seo搜索引擎优化就业前景
  • 河北seo网站开发什么是seo文章
  • 政府网站建设与管理规范淘宝推广工具
  • 重庆品牌网站建设公司苏州网站优化公司
  • php+mysql div+css网站建设 东莞域名查询seo
  • 阿里云网站建设 部署与发布考试百度论坛
  • 做网站哪个系统最好安卓优化大师手机版下载
  • 小型服务器做网站东莞排名优化团队
  • 网站建设的实验原理自助建站免费建站平台
  • 什么网站推广比较好建立网站步骤
  • 如何建立和设计公司的网站域名搜索引擎入口
  • 衡水网站建设服务沪深300指数基金
  • 都匀住房和城乡建设厅网站超链接友情外链查询
  • 百捷网站建设企业网站建设推广
  • 中央建设的最大未成年网站搜索引擎优化的流程是什么
  • 危机舆情公关公司苏州seo网络推广