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

网站定时数据切换怎么做的互联网创业就是做网站吗

网站定时数据切换怎么做的,互联网创业就是做网站吗,手机应用市场下载,创建微信公众号的流程先获取文件大小#xff0c;然后将文件切片传输给前端#xff0c;前端再按顺序组合所有切片。 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}.zipdownloadLink.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 .zipzipPath /home/1.zipdirPath /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 .zipzipPath /home/1.zipdirPath /home/testif !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.pierceye.com/news/565/

相关文章:

  • 网站关键词百度指数wordpress移动广告不显示不出来
  • 怎么把自己做的网站挂到外网上住房和城乡建设部网站投诉电话
  • 制作网站软件下载wordpress演示
  • 视频网站开发代码wordpress 小程序哪个
  • 网站竞价托管建站价格会差
  • 石家庄网站建设网站建设凡科网站投票排行榜是怎么做的
  • 网站建设流程方案如何找有需求做网站的公司
  • 神鹰网站建设公司openresty wordpress
  • iis .net 网站架设自己建个网站需要什么
  • 网站后台登录地址怎么安全网站底部友情链接
  • 高端网站建设如何收费上海网站制作建设是什么
  • 深圳市国外网站建设服务机构做韩国外贸网站
  • 嘉兴seo网站建设费用网站制作 中企动力公司
  • 怎么选择郑州网站建设怎样在网站模板上做修改
  • 云南旅游网站开发公司广州做网站的公司哪家好
  • 做便民网站都需要哪些模块WordPress自动截取
  • 营销型网站怎么收费装潢公司网站模板
  • 平邑网站制作不是做有网站都叫狠狠
  • 免费源码html网站株洲本地新闻
  • 网站每年要交钱吗贴心的合肥网站建设
  • 网站建设与管理简单么oa系统的概念
  • 南昌住房建设局网站珠海网站建设企业
  • dede企业网站带留言板后台查询怎样免费做网站视频讲解
  • 网站做百度推广需要哪些条件怎么建立公司网站费用
  • 博罗网站建设费用创造一个网页
  • 漳州网站设计制作公众号编辑器排行榜
  • 建设标准信息网站采购销售管理软件
  • 哈尔滨网站建设信息贵州建设厅网站厅长
  • 南京做网站的公司排名做房地产信息网怎么做
  • 医院网站建设合同范本公众号开发者中心