Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This server class provides methods that allow operating the attachmentsДанный серверный класс включает в себя методы, позволяющие пользователям настраивать взаимодействие с вложениями.

SimpleAttachment()


Instantiates a new empty SimpleAttachment objectИспользуйте этот метод для создания пустого объекта SimpleAttachment.


Code Block
languagejs
themeEclipse
titleSimpleAttachment
linenumberstrue
const attach = new SimpleAttachment();


base64Decode(data)

This method returns an ASCII string decoded from the base64 string specified.

Parameter(s):


Этот метод возвращает строку ASCII, декодированную из указанной строки base64.


Параметры:

НазваниеТипОбязательныйЗначение по умолчаниюNameTypeMandatoryDefault Value
dataStringYДаNНет


ReturnВозвращаемое значение:

TypeТипDescriptionОписание
StringA decoded string.Декодированная строка

ПримерExample:

Code Block
languagejs
themeEclipse
titlebase64Decode
linenumberstrue
const attach = new SimpleAttachment();
const result =
  attach.base64Decode('TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQ=');
ss.info(result);


base64Encode(data)

This method returns a Base64 string from the string specified.

Parameter(s):


Этот метод возвращает строку Base64 из указанной строки.


Параметры:

НазваниеТипОбязательныйЗначение по умолчаниюNameTypeMandatoryDefault Value
dataStringYДаNНет


ReturnВозвращаемое значение:

TypeТипDescriptionОписание
StringAn encoded Закодированная строка Base64 string.

ExampleПример:

Code Block
languagejs
themeEclipse
titlebase64Encode
linenumberstrue
const attach = new SimpleAttachment();
const result =
  attach.base64Encode('Lorem ipsum dolor sit amet');
ss.info(result);

copy(sourceTableName, sourceID, targetTableName, targetID)

This method copies attachments from the source record to the target record.

Parameter(s):


Используйте этот метод, чтобы скопировать вложения из исходной записи в целевую. 


Параметры:

НазваниеТипОбязательныйЗначение по умолчаниюNameTypeMandatoryDefault Value
sourceTableNameStringYДаNНет
sourceIDStringYДаNНет
targetTableNameStringYДаNНет
targetIDStringYДаNНет


ReturnВозвращаемое значение:

TypeТипDescriptionОписание
BooleanThis method returns 'true' if attachments have been copied successfully; otherwise, it returns 'false'.Метод возвращает true,если вложения были успешно скопированы. В случае ошибки метод возвращает false.


ПримерExample:

Code Block
languagejs
themeEclipse
titlecopy
linenumberstrue
const attach = new SimpleAttachment();
attach.copy('sys_email', '155964310500000059', 'task', current.sys_id);

deleteAttachment(attachmentID)

This method deletes the specified attachment.

Parameter(s):


Используйте этот метод, чтобы удалить указанное вложение.


Параметры:

НазваниеТипОбязательныйЗначение по умолчаниюNameTypeMandatoryDefault Value
attachmentIDStringYДаNНет


ReturnВозвращаемое значение:

TypeТипDescriptionОписание
VoidThis method does not return a valueМетод не возвращает значение.


ExampleПример:

Code Block
languagejs
themeEclipse
titledeleteAttachment
const attach = new SimpleAttachment();
attach.deleteAttachment('157052637119478714');

getAttachmentUrlById(attachmentId)

This method allows getting the URL of the specified attachment at the cloud storage.

Parameter(s):


Используйте этот метод, чтобы получить URL указанного вложения в облачном хранилище.


Параметры:

НазваниеТипОбязательныйЗначение по умолчаниюNameTypeMandatoryDefault Value
attachmentIdstringYДаNНет


ReturnВозвращаемое значение:

TypeТипDescriptionОписание
StringThis method returns the attachment URL in the cloud storage.Этот метод возвращает URL-адрес вложения в облачном хранилище.

ПримерExample:

Code Block
languagejs
themeEclipse
titlegetAttachmentUrlById
linenumberstrue
const current = new SimpleRecord('sys_attachment');
current.get('163553718313772587');
const ATTACH_ID = current.sys_id;

const simpleAttach = new SimpleAttachment();
const attachUrl = simpleAttach.getAttachmentUrlById(ATTACH_ID);
ss.info(attachUrl);
//Info: https://s3-{your-instance-url}/public-attachment/5/32/9bnc2pcb3axyfatgtc6lsi7...

getContent(sysAttachment)

This method gets the attached content as a string.

Parameter(s):


Используйте данный метод, чтобы получить содержимое вложения в виде строки.


Параметры:

НазваниеТипОбязательныйЗначение по умолчаниюNameTypeMandatoryDefault Value
sysAttachmentSimpleRecordYДаNНет


ReturnВозвращаемое значение:

TypeТипDescriptionОписание
StringThe attachment content as a string.Содержание вложения в виде строки


ПримерExample:

Code Block
languagejs
themeEclipse
titlegetContent
linenumberstrue
const attach = new SimpleAttachment();
const content = attach.getContent('157052637119478714');


readBase64(attachmentId)


This method allows getting an encoded string from the specified attachmentЭтот метод позволяет получить закодированную строку из указанного вложения.

Note

The attachment size is limited up to 10 Mb; otherwise, the method throws an exception: File size exceeded allowed limit.

Parameter(s):

Размер вложения не должен превышать 10 Mb. В случае превышения метод возвращает исключение: Размер файла превышает допустимый лимит.


Параметры:

НазваниеТипОбязательныйЗначение по умолчаниюNameTypeMandatoryDefault value
attachmentIdStringYДаNНет


ReturnВозвращаемое значение:

TypeТипDescriptionОписание
StringA base64-encoded string.Закодированная строка Base64

Пример:

Code Block
languagejs
themeEclipse
titlereadBase64
linenumberstrue
const read = new SimpleAttachment();
ss.info(read.readBase64('159050716911764097'));

rename(attachmentId, fileName)

This method renames the specified attachment.

Parameter(s):


Используйте этот метод, чтобы изменить название указанного вложения. 


Параметры:

НазваниеТипОбязательныйЗначение по умолчаниюNameTypeMandatoryDefault Value
attachmentIdStringYДаNНет
fileNameStringYДаNНет


ReturnВозвращаемое значение:

TypeТипDescriptionОписание
VoidThis method does not return a valueМетод не возвращает значение.


ExampleПример:

Code Block
languagejs
themeEclipse
titlerename
linenumberstrue
const DOC_ID = ss.getDocIdByIds(current.sys_db_table_id, current.sys_id);
const simpleAttach = new SimpleAttachment();
const attachRecord = new SimpleRecord('sys_attachment');
attachRecord.addQuery('record_document_id', DOC_ID);
attachRecord.addQuery('mime_content_type', 'application/json');
attachRecord.selectAttributes('sys_id');
attachRecord.query();
attachRecord.next();
simpleAttach.rename(attachRecord.sys_id, `${current.number} - ${current.subject}.json`);

write(documentId, fileName, content, contentType)

This method inserts an attachment to the record specified.

Parameter(s):


Используйте данный метод, чтобы добавить вложение в указанную запись.


Параметры:

НазваниеТипОбязательныйЗначение по умолчаниюNameTypeMandatoryDefault Value
documentIdStringYДаNНет
filenameStringYДаNНет
contentStringYДаNНет
contentTypeStringYДаNНет


ReturnВозвращаемое значение:

TypeТипDescriptionОписание
StringThe Метод возвращает sys_ID of the attachment; in case of an error, it returns NULL.вложения; в случае ошибки возвращает null.

ПримерExample:

Code Block
languagejs
themeEclipse
titlewrite
linenumberstrue
const simpleAttach = new SimpleAttachment();
const attachID =
    simpleAttach.write(
        ss.getDocIdByIds(current.sys_db_table_id, current.sys_id),
        'readme.json',
        JSON.stringify(current.getAttributes(), null, '\t'),
        'application/json'
    );

writeBase64(documentId, fileName, base64, contentType)

This method inserts the attachment to the record specified using the Base64 encoding.

Parameter(s):


Данный метод предназначен для добавления вложения к указанной записи при помощи кодирования Base64.


Параметры:

НазваниеТипОбязательныйЗначение по умолчаниюNameTypeMandatoryDefault Value
documentIDStringYДаNНет
fileNameStringYДаNНет
base64StringYДаNНет
contentTypeStringYДаNНет


ReturnВозвращаемое значение:

TypeТипDescriptionОписание
String or или NULLThe Метода возвращает sys_ID of the attachment; in case of an error, it returns NULL.вложения;в случае ошибки возвращает null.

ПримерExample:

Code Block
languagejs
themeEclipse
titlewriteBase64
linenumberstrue
const CURRENT_USER_DOC_ID = ss.getDocIdByIds(ss.getUser().sys_db_table_id, ss.getUserID());
const simpleAttach = new SimpleAttachment();
const base64Value = 'R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=';
const attachId = simpleAttach.writeBase64(
    CURRENT_USER_DOC_ID,
  	'file_example.gif',
    base64Value,
    'image/gif'
);
ss.info(attachId);
//Info: 162245472311776172


Table of Contents
absoluteUrltrue
classfixedPosition