CreateDocumentWithAttachmentFromWeb
≥4.8.1
Interface Function
Upload attachments and create Document via web pages; workflow can be executed by assigning a value to the ActionCode parameter.
Note
The interface Content-Type should be
multipart/form-data;
, which is specified by form.Refer to the below demo. The interface function is the same as CreateDocumentWithAttachment, but the parameter types are different. In CreateDocumentWithAttachment, you can use the string type of file transfer to Base64 and initiate the call in json format. This method is more suitable for the situation when there is a file control in the form.
Request Parameter
Parameter | Type | Remarks |
---|---|---|
file | String | File control content |
data | String | Other necessary information besides attachments |
Request Data Description
Field Name | Type | Remarks |
---|---|---|
FormAlias | String | Form alias, the identity of the form |
DataId | String | Document ID, GUID without underscore, can be empty and automatically generated when the interface is empty. |
UserName | String | When creating a new creation, the creator/modifier, and when modifying, it is the modifier. If the UserName is incorrect, but the ActionCode is set, the Workflow Action cannot be executed correctly |
UserId | String | Staff Code, when creating a new creation, assign a value to the attribute of the creator, when modifying, assign a value to the attribute of the modified person. If the parameter is incorrect, but the ActionCode is set, the Workflow Action cannot be executed correctly |
AttachmentFieldName | String | The corresponding control Field name of the attachment in the Form |
TransferToPDF | Bool | Whether to convert the attachment to PDF, true by default. Start to support 4.5.1. This field forces false if the attachment control is a secure upload control. |
ActionCode | String | ActionCode of Workflow button |
ActionMessage | String | Workflow action message |
Data | Dictionary<string, object> |
Attachment information. See the below table for detailed fields. |
DocumentData | Dictionary<string, string> |
Document history information, which can be displayed in the Edit History component. |
Attachment Data Descriptions
Field Name | Type | Remarks |
---|---|---|
fileName | string | File name |
fileUUID | string | The file identifier can be specified as a GUID. If not specified, the interface is automatically generated. The attachment can be downloaded by calling DownloadAttachment through this field. |
[info] Note
- When the specified FormAlias does not exist, the interface returns an error message.
- When the specified DataId does not exist, a new document is created based on the specified DataId.
Return Data Type
Data type is string when operation fails, 1 is for success, and other values are for failure. Return data type when all operations are completed:
UploadAttachmentResult
.
Field Name | string | Remarks |
---|---|---|
entityName | string | Form alias, the identity of the form |
dataId | string | DocumentvID |
result | string | Operation result |
msg | string | Operation result description |
Note
The attachment types that can be converted to PDF are: "JPG","BMP","PNG","GIF","PPTX","PPT","XLSX","XLS","DOCX","DOC"," VSDX","VSD","PDF".
The attachment types that can be converted to HTML are: "PPTX","PPT","XLSX","XLS","DOCX","DOC","PDF","CSV","JPG","JPEG","PNG".
The system will judge the type of the corresponding control according to the specified AttachmentFiledName, and automatically process the logic of converting to html. Also note: Converting to HTML and PDF are mutually exclusive.
When the TransferToPDF parameter is set to "true", the interface will judge the attachment format type. If the attachment format is a type supported by the system, a PDF preview file will be automatically generated and saved after uploading, otherwise an error message will be returned.
When the TransferToPDF parameter is set to "false", the interface does not check the attachment format type and does not generate a PDF preview file.
This method does not support fragment upload.
Request Sample
<!--Note: the attribute of form enctype needs to be specified as multipart/form-data.-->
<form enctype= "multipart/form-data" ID="form1">
<input type="file" id="file" name="file">
<input type="button" value="submit" onclick="uploadFile()">
</form>
function uploadFile(){
var ofile = $("#file").get(0).files[0];
var formData = new FormData();
if(!ofile){
alert('Please upload file!','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,//Indicates that data are not serialized when submitting, but data are used directly, which is true by default.
contentType: false,
success: function(data){
console.log(data);
}
});
}
Return Sample
{
"StatusCode": 200,
"Info": "Request (or process) succeeded",
"Data": {
"entityName": "DemoFormAlias",
"dataId": "94635f2b5ae24fa28d6ca3ab5c96f8c9",
"result": 1,
"msg": "Process successed"
}
}