uploadAttachment(file, onUploadProgress, errorHandler, context)
Uploads a file to the server.
Returns
A Promise that uploads a file to the server.
Parameters
Name | Type | Description | Required |
file | object | The file that needs to be uploaded to the server. | ✅ |
onUploadProgress | function | A callback function that obtains the upload progress of the file. | ✅ |
errorHandler | function | A callback function to handle exceptions. | ✅ |
context | string | The name of the context where the API is being called. | ✅ |
Usage example
In this example, the API uploads a file to the server.
const onUploadProgress = (ev) => {
// ev is a progress type event
// which has total, loaded properties to calculate progress
}
const errorHandler = (error) => {
// handle error here
}
PCore.getAttachmentUtils().uploadAttachment(file, onUploadProgress, errorHandler , 'app/primary_1')
.then((fileResponse) => {
const fileId = fileResponse.data.ID;
}).catch(err => {
// Error handling
});
Previous topic linkAttachmentsToCase(caseID, attachments, attachmentType, context) Next topic APIs in the AuthUtils module