You are viewing an old version of this page. View the current version.
Compare with Current View Page History
« Previous Version 34 Next »
This server class provides methods that allow operating with attachments.
SimpleAttachment()
Instantiates a new empty SimpleAttachment object.
const attach = new SimpleAttachment();
base64Decode(data)
This method returns an ASCII string decoded from the base64 string specified.
Name | Type | Mandatory | Default Value |
---|---|---|---|
data | String | Y | N |
Return:
Type | Description |
---|---|
String | The decoded string. |
Example:
const attach = new SimpleAttachment(); attach.base64Decode('TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdCwgc2VkIGRvIGVpdXNtb2QgdGVtcG9yIGluY2lkaWR1bnQgdXQgbGFib3JlIGV0IGRvbG9yZSBtYWduYSBhbGlxdWEuIA==');
base64Encode(data)
This method returns a Base64 string from the string specified.
Name | Type | Mandatory | Default Value |
---|---|---|---|
data | String | Y | N |
Return:
Type | Description |
---|---|
String | The encoded Base64 string. |
Example:
const attach = new SimpleAttachment(); attach.base64Encode('Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. ');
copy(sourceTable, sourceID, targetTable, targetID)
This method copies attachments from the source record to the target record.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
sourceTable | String | Y | N |
sourceID | String | Y | N |
targetTable | String | Y | N |
targetID | String | Y | N |
Return:
Type | Description |
---|---|
Void | This method does not return a value. |
Example:
const attach = new SimpleAttachment(); attach.copy('sys_email', '155964310500000059', 'task', '155964310500000051');
createAttachmentByUrl(url, SimpleRecordId, fileName)
This method allows to get a file from remote instance by an URL provided.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
url | String | Y | N |
SimpleRecordId | String | Y | N |
fileName | String | Y | N |
Return:
Type | Description |
---|---|
String | This method returns the attachment ID in the cloud storage; if not created, returns NULL. |
Example:
const attach = SimpleAttachmentService(); attach.setUrl('http://simple.test'); attach.setUsername('admin'); attach.setPassword('123456'); const sysId = attach.createAttachmentByUrl('http://simple.test/v1/attachments/download/159229954513242397', '0229fa8a-bcbe-1f54-0229-fa8abcbe1f01', 'test.sop');
deleteAttachment(attachmentID)
This method deletes the specified attachment.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
attachmentID | String | Y | N |
Return:
Type | Description |
---|---|
Void | This method does not return a value. |
Example:
const attach = new SimpleAttachment(); attach.deleteAttachment('157052637119478714');
getAttachmentUrlById(attachmentId)
This method allows to get the URL of the specified attachment at the cloud storage.
Name | Type | Mandatory | Default Value |
---|---|---|---|
attachmentId | string | Y | N |
Return:
Type | Description |
---|---|
String | This method returns the attachment URL in the cloud storage. |
Example:
const attach = new SimpleAttachment(); const publicUrl = attach.getAttachmentUrlById('157052637119478714'); ss.info(publicUrl);
getContent(sysAttachment)
This method gets attachment content as a string.
Name | Type | Mandatory | Default Value |
---|---|---|---|
sysAttachment | SimpleRecord | Y | N |
Return:
Type | Description |
---|---|
String | The attachment content as a string. |
Example)
const attach = new SimpleAttachment(); const content = attach.getContent('157052637119478714');
readBase64(attachmentId)
This method allows to get a encoded string from the specified attachment.
The attachment size is limited up to 10 Mb; otherwise, the method throws an exception.
Parameter(s):
Name | Type | Mandatory | Default value |
---|---|---|---|
attachmentId | String | Y | N |
Return:
Type | Description |
---|---|
String | The base64-encoded string. |
const read = new SimpleAttachment(); ss.info(read.readBase64('159050716911764097'));
rename(attachmentId, fileName)
This method renames the specified attachment.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
attachmentId | String | Y | N |
fileName | String | Y | N |
Return:
Type | Description |
---|---|
Void | This method does not return a value. |
Example:
const attach = new SimpleAttachment(); attach.rename('157052637119478714', 'new_name_1.png');
write(record, fileName, contentType, content)
This method inserts the attachment to the record specified.
Name | Type | Mandatory | Default Value |
---|---|---|---|
record | SimpleRecord | Y | N |
filename | String | Y | N |
contentType | String | Y | N |
content | String | Y | N |
Return
Type | Description |
---|---|
String | The attachment's sys ID. |
Example:
const attach = new SimpleAttachment(); const record = attach.write('157052637119478714', 'readme.md', 'text/markdown', '# h1 title');
writeBase64(documentId, fileName, base64, contentType)
This method inserts the attachment to the record specified using Base64 encoding.
Name | Type | Mandatory | Default Value |
---|---|---|---|
documentID | String | Y | N |
fileName | String | Y | N |
base64 | String | Y | N |
contentType | String | Y | N |
Return
Type | Description |
---|---|
String or NULL | The attachment's sys ID; in case of error; returns NULL. |
Example:
const write = new SimpleAttachment(); const base64 = 'iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAYAAABccqhmAAAABHNCSVQICAgIfAhkiAAABYFJREFUeJzt3SGQVVUcwOGLQyDSoGkDGyRpYnJIaFpIQDLiNrdh2jE5NE1Ic5smJaHRJLSlSdNGpGl2TOfIu+/xft+X75lzF977zQnvP+fMwt64uSx/b/sdtunHZTmz7Xd427yz7RcAtkcAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIMzwxErWGNQ5+fD+preY9+3g85+Nb3Hw68PhNfUBIicACBMACBMACBMACBMACBMACBMACBMACBMACBMACBMACBMACDu77Rd4G80M9qwxqPPTn682vseyLMv7X5wOr3lvuTa24MlXw3ss58aHgeqcACBMACBMACBMACBMACBMACBMACBMACBMACBMACBMACAsfSnCssz9rv/upTvD+9y4eH7o+bV+1//pi8er7LNn9uZ74wQAYQIAYQIAYQIAYQIAYQIAYQIAYQIAYQIAYQIAYQIAYQIAYXsz1LAs6w32rMGQzt7Zye+aEwCECQCECQCECQCECQCECQCECQCECQCECQCECQCECQCECQCEnd32C2zbjZO7w2vOXfnozb/IG/D6/mfDa849/HYn95ncYycHbnaZEwCECQCECQCECQCECQCECQCECQCECQCECQCECQCECQCECQCE7ezwxMwtPyfPng7v8/XxreE1h0ffD68ZHSCaGYZZ7o3/LTODTa8n/p2H//6V/i9nHJ38tbPfm1FOABAmABAmABAmABAmABAmABAmABAmABAmABAmABAmABAmABC2XzcDPRof0tlVUzf2TAwDzQzdzFhjn5khrTm3hgfVdnWAyAkAwgQAwgQAwgQAwgQAwgQAwgQAwgQAwgQAwgQAwgQAwvZqFmDq9/MzF3CsYK3f6E9dDLKj/2aMcwKAMAGAMAGAMAGAMAGAMAGAMAGAMAGAMAGAMAGAMAGAMAGAsJ28rOB/GL6wYcYqwzATl3zMDPYwZW++N04AECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAELY3Qw3/w/AA0fHBhU28x78cXvxk43vMmrmBaYelvwNOABAmABAmABAmABAmABAmABAmABAmABAmABAmABAmABAmABCWHoSYdXNigOjupTtDz59e+Xl0i532zennQ8+/fH7ks7kCJwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIyw9crDHYM+PGxfPDaz6+fnkDb/Jf129f3fge3x08HV5jgGicEwCECQCECQCECQCECQCECQCECQCECQCECQCECQCECQCEnd32C7yN1ri043Rq1YPhFU+O7k3tNOr4j2dDz7/47XB4j0sfjM911OcHnAAgTAAgTAAgTAAgTAAgTAAgTAAgTAAgTAAgTAAgTAAgTAAgLD8MdO3gwvCaw8cvN/Amb8CddycWrTMMxG5yAoAwAYAwAYAwAYAwAYAwAYAwAYAwAYAwAYAwAYAwAYAwAYCw/DDQrvp6YrDn58sPxtccPxpeM+P67atDz4/eJMQcJwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIMwzEsD9+eDW85pfl943v8fL50ZnhRXFOABAmABAmABAmABAmABAmABAmABAmABAmABAmABAmABAmABBmeGLC8cGFv7f9Dm/K0clfw2uODy6ssY/P5gqcACBMACBMACBMACBMACBMACBMACBMACBMACBMACBMACDM763nDM8CzPx+fg2HX94aXnPu8sPhNa9P7298j8XneZgTAIQJAIQJAIQJAIQJAIQJAIQJAIQJAIQJAIQJAIQJAIQJAIQZnpizNxeD7Bmf50FOABAmABAmABAmABAmABAmABAmABAmABAmABAmABAmABAmABD2D4/fmKms6poKAAAAAElFTkSuQmCC'; const ico = write.writeBase64('mario.png', base64, 'image/png', '156819163902483433'); ss.info(ico);
- No labels