CreateDocumentWithAttachmentFromWeb
≥4.8.1
不支持在CustomiseAPI中使用WebApi Service的方式调用
接口描述
通过web页面上传附件并创建Doc,可通过给 ActionCode 参数赋值同时执行workflow
说明
该接口Content-Type应该是
multipart/form-data;,该值通过form指定。 可参考下文demo。 接口功能同CreateDocumentWithAttachment相同,但是参数类型不同,CreateDocumentWithAttachment中可以使用文件流转Base64的string类型, 以json格式发起调用, 本方法比较适合当form中有file控件的情况。
参数类型
| 参数 | 类型 | 说明 | 
|---|---|---|
| file | String | file控件内容 | 
| data | String | 除附件外其他必要信息 | 
data说明
| 字段名 | 类型 | 说明 | 
|---|---|---|
| FormAlias | String | Form别名, Form的标识 | 
| DataId | String | 文档ID,无下划线的GUID,可为空,为空时接口自动生成 | 
| UserName | String | 新建时,创建人/修改人,修改时为修改人.UserName如果不正确,但是设置了ActionCode, Workflow的Action不能正确执行 | 
| UserId | String | Staff Code, 新建时,为创建人属性赋值,修改时为修改人属性赋值, 该参数如果不正确,但是设置了ActionCode, Workflow的Action不能正确执行 | 
| AttachmentFieldName | String | 附件在Form中对应的控件Field name | 
| TransferToPDF | Bool | 是否将附件转为PDF,默认为 true。4.5.1开始支持。如果附件控件为安全上传控件,则该字段会被忽略。 | 
| ActionCode | String | Workflow button的ActionCode | 
| ActionMessage | String | Document 历史信息,可使用Edit History组件中展示 | 
| Data | Dictionary<string, object> | 附件信息,具体字段见下表 | 
| DocumentData | Dictionary<string, string> | 文档其他字段字典 | 
附件Data说明
| 字段名 | 类型 | 说明 | 
|---|---|---|
| fileName | string | 文件名 | 
| fileUUID | string | 文件标识,可以指定GUID作为值,若不指定,接口自动生成。可通过该字段调用 DownloadAttachment下载附件。 | 
[info] 提示
- 指定的 FormAlias 不存在时,接口返回错误信息
- 指定的 DataId 不存在时,将根据指定的 DataId 创建新文档
返回参数类型
操作失败时数据类型为string,1为成功,其他值失败。 所有操作都完成时返回的数据类型:
UploadAttachmentResult
| 字段名 | string | 说明 | 
|---|---|---|
| entityName | string | Form别名, Form的标识 | 
| dataId | string | document的ID | 
| result | string | 操作结果 | 
| msg | string | 操作结果描述 | 
说明
支持转为
"JPG","BMP","PNG","GIF","PPTX","PPT","XLSX","XLS","DOCX","DOC","VSDX","VSD","PDF"。支持转为
HTML的附件类型为:"PPTX","PPT","XLSX","XLS","DOCX","DOC","PDF","CSV","JPG","JPEG","PNG"。系统会根据指定的
AttachmentFiledName判断对应控件的类型,并自动处理转为html的逻辑。同时注意:转HTML和转PDF互斥。TransferToPDF参数设置为 true 时,接口会判断附件格式类型,如果附件格式为系统支持的类型,则上传完成后会自动生成PDF预览文件保存,否则返回错误提示。
TransferToPDF参数设置为 false 时,接口不检查附件格式类型,也不生成PDF预览文件。
该方法不支持分片上传。
请求示例
<!--注意,此处的form enctype属性需要指定为 multipart/form-data-->
<form enctype= "multipart/form-data" ID="form1">
    <input type="file" id="file" name="file">
    <input type="button" value="提交" onclick="uploadFile()">
</form>
 function uploadFile(){
    var ofile = $("#file").get(0).files[0];
    var formData = new FormData();
    if(!ofile){
        alert('请上传文件!','info');
        return; 
    }
    var data=JSON.stringify({
            "FormAlias": "DemoFormAlias",
            "DataId": "",
            "UserName": "DemoUser",
            "UserId": "DemoUser",
            "ActionCode": "",
            "ActionMessage": "",
            "AttachmentFieldName": "File",
            "TransferToPDF":true,
                "Data": {
                "fileName": "",
                "fileUUID": ""
            },
            "DocumentData": {
                "OtherField": "demo"
            }
    });
    formData.append("file", ofile);
    formData.append("data", data);
        $.ajax({
            url: '/demotenant/demoapp/customapi/CreateDocumentWithAttachmentFromWeb',
            type: "POST",
            data: formData, 
            cache: false,
            processData: false,//表示提交的时候不会序列化 data,而是直接使用 data,默 true
            contentType: false,
            success: function(data){
            console.log(data);
        }
    });
}
返回示例
{
      "StatusCode": 200,
      "Info": "Request (or process) succeeded",
      "Data": {
            "entityName": "DemoFormAlias",
            "dataId": "94635f2b5ae24fa28d6ca3ab5c96f8c9",
            "result": 1,
            "msg": "Process successed"
      }
}