ftos.files.upload
IMPORTANT!
Starting with v24.3.0, this is renamed from uploadFile to ftos.files.upload.
Starting with v24.3.0, this is renamed from uploadFile to ftos.files.upload.
Saves an encoded file to the default upload folder or to a known folder. The file can be structured file object with metadata, raw binary data, or path, URL, or encoded content. base64 is also used.
This is a business logic method for business service components.
Syntax
Copy
function ftos.files.upload(options : IEbsUploadFileOptions, file: any): FileUploadInfo
| Parameter | Type | Description |
|---|---|---|
options
|
IEbsUploadFileOptions | Name and location of the file to be uploaded. |
FileUploadInfo
|
string | Contents of the file encoded. It can be string, WorkflowBlob, Uint8Array. |
Interface
Name and location of the file to be uploaded.
Copy
{
fileName : string;
uploadLocation? : any;
}
| Property | Type | Description |
|---|---|---|
fileName
|
string | Name of the file that will be uploaded, including the file extension. |
uploadLocation (optional) |
any | Name of the known folder:
|
Return Value
Returns a JSON object detailing the file upload with the following structure:
Copy
{
"Name": "backup.pdf",
"RealName": "backup_65d697c9-ab55-4737-a720-79c031867cc1.pdf",
"IsSuccess": true,
"Message": null,
"ClientScript": null,
"Serialized": null,
"ErrorCode": 0,
"UIResult": null
}
Examples
In this example:
- We make a backup of the contract_df7022c8-4fb3-4353-9fa8-bb2514e3a6ea.pdf file. For information on how to get the Base64 encoded contents of a file, see ftos.files.download.
- We save the backup in a file called backup.pdf.
- We store the upload details in a variable called upload.
- If the upload is successful, we display a success notification. For details on how to display notifications, see ftos.context.response.setMessage.
- If the upload fails, we display a failure alert. For details on how to display alerts, see ftos.context.response.setMessage.
Copy
var upload = ftos.files.upload('backup.pdf', ftos.files.download('contract_df7022c8-4fb3-4353-9fa8-bb2514e3a6ea.pdf'));
if (upload.IsSuccess) {
ftos.context.response.setMessage(upload.Name + ' successfuly saved.', true);
}
else {
ftos.context.response.setMessage('Upload failed.', false);
}
In this example:
- We make a backup of the Contract_b81ea359-55d6-494d-8bd0-95788170ffde.pdf file. For information on how to get the Base64 encoded contents of a file, see ftos.files.download.
- We save the backup in a file called contractBackup.pdf in the Processed known folder.
- We store the upload details in a variable called upload.
- If the upload is successful, we display a success notification. For details on how to display notifications, see ftos.context.response.setMessage.
- If the upload fails, we display a failure alert. For details on how to display alerts, see ftos.context.response.setMessage.
Copy
var upload = ftos.files.upload({fileName:'contractBackup.pdf', uploadLocation:'Processed'}, ftos.files.download('Contract_b81ea359-55d6-494d-8bd0-95788170ffde.pdf'));
if (upload.IsSuccess) {
ftos.context.response.setMessage(upload.Name + ' successfuly saved.', true);
}
else {
ftos.context.response.setMessage('Upload failed.', false);
}