zoukankan      html  css  js  c++  java
  • 上传模型方法-断点续传方法

    /// <summary>
    /// 上传模型方法-断点续传方法
    /// </summary>
    /// <returns></returns>
    public string AddUpload()
    {
    JsonResult json = new JsonResult();
    json.status = false;
    try
    {
    var modelName = HttpContext.Current.Request["modelName"].ToString();
    var filetype = HttpContext.Current.Request["filetype"].ToString();
    var importType = HttpContext.Current.Request["importType"].ToString();
    int importTypeID = int.Parse(importType);//1 新增或覆盖 2 同名称追加模型 append
    
    
    if (HttpContext.Current.Request.Files.Count <= 0)
    {
    json.msg = "未识别到上传的文件";
    return JsonConvert.SerializeObject(json);
    }
    HttpPostedFileBase fileBase = new HttpPostedFileWrapper(HttpContext.Current.Request.Files[0]) as HttpPostedFileBase;
    long len = fileBase.ContentLength;
    string extensionName = System.IO.Path.GetExtension(fileBase.FileName); //获取文件扩展名
    string fileName = System.IO.Path.GetFileName(fileBase.FileName); //获取文件名
    /////可增加文件格式判断逻辑
    if (extensionName.ToUpper() == filetype.ToUpper())
    {
    //第一步 创建服务ID
    var taskID = CreateUpLoadModelTask(modelName);
    
    //第二步 上传文件
    
     
    
    byte[] bytes = new byte[1024000];//每次分割大小1m 根据情况自由调节,建议10M以内
    bool blUplload = true;
    using (BinaryReader reader = new BinaryReader(fileBase.InputStream, System.Text.Encoding.UTF8))
    {
    while (reader.Read(bytes, 0, bytes.Length) > 0)
    {
    blUplload = blUplload && UpLoadModel(bytes, fileName, taskID, bytes.Length);
    }
    }
    
    if (blUplload)
    {
    // 第三步 后台格式转换
    ConvertAndUpdateModel(taskID, importTypeID);
    //第四步:
    json.status = InsertModelData(modelName, modelName);
    }
    else
    {
    json.msg = "上传文件失败!";
    }
    
    if (UpLoadModel(bytes, fileName, taskID, len))
    {
    //第三步 后台格式转换
    ConvertAndUpdateModel(taskID, importTypeID);
    //第四步:
    
    json.status = InsertModelData(modelName, modelName);
    }
    else
    {
    json.msg = "上传文件失败!";
    }
    
    
    }
    else
    {
    json.msg = "请上传文件与选定类型不一致";
    }
    
    }
    catch (Exception ex)
    {
    json.msg = "服务错误:" + ex.ToString();
    
    }
    return JsonConvert.SerializeObject(json);
    }
  • 相关阅读:
    quartz 时间表达式----- Cron表达式详解
    js正则表达式
    tomcat的server.xml文件的详解
    spring web.xml中 过滤器(Filter)的工作原理和代码演示
    tomcat端口占用解决方案
    Spring集成Hibernate映射文件的4种方式
    Hibernate 一二级缓存的使用场景
    Hibernate各种主键生成策略
    Pip的安装,环境变量的配置以及使用方法
    解决pycharm无法调用pip安装的包
  • 原文地址:https://www.cnblogs.com/efreer/p/13504091.html
Copyright © 2011-2022 走看看