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);
    }
  • 相关阅读:
    应对IBM V7000磁盘故障,你只差这一步!
    鬼知道我经历了什么;记阵列RAID信息丢失的恢复过程
    遇到U盘无法打开,属性显示0字节这样的问题?数据该如何导出?
    2、【Linux网络编程】socket中sockaddr、sockaddr_in和in_addr的区别
    1、【Linux网络编程】socket
    9、wxWidgets 组件wxListBox wxNotebook wxScrolledWindow
    8、wxWidgets 组件wxCheckBox wxBitmapButton wxToggleButton wxStaticLine wxStaticText wxSlider
    7、wxWidgets 对话框
    6、wxWidgets 事件处理
    5、wxWidgets布局管理
  • 原文地址:https://www.cnblogs.com/efreer/p/13504091.html
Copyright © 2011-2022 走看看