• 上传模型方法-断点续传方法


    /// <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);
    }
  • 相关阅读:
    html5 存储方式
    分割字符串得到分数,然后求和取整
    通过javascript的日期对象来得到当前的日期
    基础选择器
    制作3D旋转视频展示区
    自由缩放属性resize
    团队项目第四天
    团队项目第三天
    团队项目第二天
    团队项目第一天
  • 原文地址:https://www.cnblogs.com/efreer/p/13504091.html
Copyright © 2020-2023  润新知