大文件分片上传

  1. 找一个数据库关联上adp的数据源

undefined

  1. 找开发确认这个数据源的sourceId,记下来(很重要,后面要用)

  2. 使用navicat进入这个mysql,然后执行以下建表语句

CREATE TABLE `t_upload_file_store` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `app_name` varchar(100) NOT NULL,
  `file_id` varchar(50) NOT NULL,
  `file_name` text,
  `file_size` int(11) DEFAULT '0',
  `part_id` varchar(50) NOT NULL COMMENT '仅分片上传使用,片段id',
  `part_idx` int(11) DEFAULT NULL COMMENT '仅分片上传有用,片段序号,从1开始',
  `part_size` int(11) DEFAULT NULL COMMENT '仅分片上传有用,片段大小',
  `content` longblob,
  `content_type` text,
  `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `fp_idx` (`file_id`,`part_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4;
  1. 建立任务 -> 建立应用 -> 在应用中建立三个接口,配置如下

undefined

undefined

undefined

上图中接口名不重要,只要start,api,finish都能对应上名字就行

重要的是目标接口URL,里面的红线标注部分,要写第2步得到的sourceId

图上的关键内容可拷贝下面文字

http://adp-internal.hylanda.com/iapi/innerApp/toolsApi/upload/chunk/SOURCEID/start-chunk
http://adp-internal.hylanda.com/iapi/innerApp/toolsApi/upload/chunk/SOURCEID/chunk-api
http://adp-internal.hylanda.com/iapi/innerApp/toolsApi/upload/chunk/SOURCEID/finish-chunk

请在完成上述4个步骤后,执行下面的操作:

  1. 先把下面的amisjson做成一个页面

下面的json里,搜索testbatchupdate这个词,替换成你的应用英文名

{
  "type": "page",
  "body": [
    {
      "filterSettingSource": [
        "id",
        "file_name",
        "report_type",
        "download_url",
        "upload_time"
      ],
      "alwaysShowPagination": true,
      "syncLocation": false,
      "perPageAvailable": [
        10
      ],
      "columns": [
        {
          "name": "id",
          "label": "id",
          "type": "text"
        },
        {
          "name": "file_name",
          "label": "文件名",
          "placeholder": "-",
          "type": "text"
        },
        {
          "name": "report_type",
          "label": "报告类型",
          "placeholder": "-",
          "type": "text"
        },
        {
          "name": "upload_time",
          "label": "上传时间",
          "placeholder": "-",
          "type": "text"
        },
        {
          "blank": true,
          "name": "download_url",
          "href": "${download_url}",
          "label": "下载链接",
          "placeholder": "-",
          "type": "link",
          "title": "点击下载文件",
          "body": "下载"
        },
        {
          "buttons": [
            {
              "actionType": "ajax",
              "level": "link",
              "className": "text-danger",
              "confirmText": "确定要删除?",
              "label": "删除",
              "api": {
                "method": "post",
                "url": "/innerApp/appApi/custom/testbatchupdate/listupfiles"
              },
              "type": "button"
            }
          ],
          "label": "操作",
          "type": "operation"
        }
      ],
      "itemActions": [
      ],
      "type": "crud",
      "features": [
        "delete"
      ],
      "bulkActions": [
        {
          "onClick": "props.data.selectedItems.forEach(function(x){window.open(x['download_url'], '_blank');});",
          "perPageAvailable": [
            10
          ],
          "label": "批量下载",
          "type": "button"
        }
      ],
      "messages": {
      },
      "api": {
        "method": "get",
        "url": "/innerApp/appApi/custom/testbatchupdate/listupfiles"
      },
      "id": "u:bc8f0121bebc",
      "placeholder": "-",
      "headerToolbar": [
        {
          "tpl": "内容",
          "label": "按钮",
          "type": "bulk-actions",
          "align": "left"
        },
        {
          "tpl": "内容",
          "actionType": "dialog",
          "dialog": {
            "type": "dialog",
            "title": "弹框标题",
            "body": [
              {
                "api": {
                  "method": "post",
                  "dataType": "json",
                  "url": "/innerApp/appApi/custom/testbatchupdate/insert-upload"
                },
                "id": "u:9b9eb8fc31cd",
                "type": "form",
                "title": "表单",
                "body": [
                  {
                    "checkAll": false,
                    "name": "report_type",
                    "options": [
                      {
                        "label": "日报",
                        "value": "日报"
                      },
                      {
                        "label": "月报",
                        "value": "月报"
                      },
                      {
                        "label": "年报",
                        "value": "年报"
                      },
                      {
                        "label": "其他",
                        "value": "其他"
                      }
                    ],
                    "label": "报告类型",
                    "type": "select"
                  },
                  {
                    "receiver": "/api/upload/file",
                    "chunkSize": 5242880,
                    "joinValues": false,
                    "finishChunkApi": "/innerApp/appApi/external/testbatchupdate/finish-chunk",
                    "multiple": true,
                    "label": "选择上传文件",
                    "type": "input-file",
                    "chunkApi": "/innerApp/appApi/external/testbatchupdate/chunk-api",
                    "btnLabel": "请选择文件",
                    "accept": "",
                    "autoUpload": true,
                    "extractValue": true,
                    "useChunk": true,
                    "name": "upload_urls",
                    "startChunkApi": "/innerApp/appApi/external/testbatchupdate/start-chunk",
                    "hideUploadButton": false,
                    "fileField": "file"
                  }
                ]
              }
            ]
          },
          "label": "批量上传",
          "type": "button",
          "align": "right"
        }
      ]
    }
  ]
}
  1. 替换chunk三接口的名字,改成你在上面第4步建立的三个接口,在json的这里

undefined

  1. 建立文件列表存储表,用navicat进入数据库,执行下列语句
CREATE TABLE `t_upload_file_list` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `file_name` text,
  `file_id` varchar(50) NOT NULL,
  `report_type` varchar(20) NOT NULL,
  `download_url` text NOT NULL,
  `upload_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4;
  1. 新建listupfiles接口

注意:不需要按图一点点抄,选好数据源,点击下面的“载入CRUD模板”按钮,然后把两个sql的表名改成上一步建立的表名

undefined

  1. 建立insert-upload接口

这个需要抄了(API参数需要完全一样,不然语句执行会报错)

sql部分如下

INSERT INTO `t_upload_file_list`(`file_name`,`file_id`,`report_type`,`download_url`) VALUES 
{% for line in upload_urls|parse_json %}
{% if loop.index0 > 0 %},{%endif%}
    ('{{line|str_split('/')|last|mysql_escape}}','{{line|str_split('/')|list_getitem(-2)|mysql_escape}}','{{report_type|mysql_escape}}','{{line|mysql_escape}}')
{% endfor %}

undefined

  1. 第4,5两步,如果完全按照图上的接口名配置,则不需要改,若接口名改成给自己定义的,则需要到amisjson里,替换自己的接口地址

共有3处:

undefined

undefined

undefined

  1. 自行补充其他逻辑即可,例如表单的必填检查,文件的删除按钮。

问题没有解决?请留言提问

results matching ""

    No results matching ""