Class Attachment
Handles Service attachments.
Syntax
Examples
Attachment a;
a.load(2); // Loads attachment with ID = 2
a.setValue("name", "test.txt");
print(a.getValue("size")); // Size in bytes
Constructors
Attachment()
Initializes a new instance of the Attachment class.
Declaration
Attachment
Examples
Attachment a;
a.load(2); // Loads attachment with id = 2
a.setValue("name", "test.txt");
print(a.getValue("size")); // Size in bytes
Methods
dump()
Dumps the attachment file to output.
Declaration
Bool dump()
Returns
Type | Description |
---|---|
Bool | True if everything is OK; otherwise false. |
Remarks
Use dump(Bool) to signal the browser to download the file instead of display it.
Examples
Attachment a;
a.load(2); // Loads attachment with ID = 2
a.setValue("name", "test.txt");
print(a.getValue("size")); // Size in bytes
dump(Bool)
Dumps the attachment file to output. The optional parameter if true tells the browser to download the file, and not attempt to display it.
Declaration
Bool dump(Bool download)
Parameters
Type | Name | Description |
---|---|---|
Bool | download | True if you want to download the file instead of display it. |
Returns
Type | Description |
---|---|
Bool | True if everything is OK; otherwise false. |
Examples
Attachment a;
a.load(2); // Loads attachment with ID = 2
a.setValue("name", "test.txt");
print(a.getValue("size")); // Size in bytes
getBase64()
Returns the attachment as base64 encoded string.
Declaration
String getBase64()
Returns
Type | Description |
---|---|
String | The attachment as base64 encoded string. |
Remarks
This can be used to load a binary attachment into a string, as base64 coded data is valid ASCII.
Examples
Attachment a;
a.load(2); // Loads attachment with ID = 2
a.setValue("name", "test.txt");
print(a.getValue("size")); // Size in bytes
getDownloadUrl(Bool,Bool)
Constructs a download URL for the attachment.
Declaration
String getDownloadUrl(Bool external, Bool saveToDisk)
Parameters
Type | Name | Description |
---|---|---|
Bool | external | The URL to be used by a customer or an user. |
Bool | saveToDisk | Is this a link used to hint to the web browser with http headers that the file is not to be opened, but saved to disk? |
Returns
Type | Description |
---|---|
String | The download URL for the attachment. |
Remarks
There are 2 kinds of URLs: external = used by customers; internal = used by Service users.
Examples
Attachment a;
a.load(2); // Loads attachment with ID = 2
a.setValue("name", "test.txt");
print(a.getValue("size")); // Size in bytes
getRaw()
Gets the whole attachment as a String without any special encoding.
Declaration
String getRaw()
Returns
Type | Description |
---|---|
String | The raw attachment without any special encoding. |
Examples
Attachment a;
a.load(2); // Loads attachment with ID = 2
a.setValue("name", "test.txt");
print(a.getValue("size")); // Size in bytes
getValue(String)
Gets a value from the attachment class.
Declaration
String getValue(String name)
Parameters
Type | Name | Description |
---|---|---|
String | name | The field to get the value for. |
Returns
Type | Description |
---|---|
String | The value of the property given in name. |
Remarks
The current implementation supports the following values as the name parameter.
- id: the attachment ID
- contentType: content descriptor
- name: the filename
- size: size in bytes
- key: authentication key
- charset
- dbiAgentId
- dbiKey
- dbiLastModified
- dbiLastSyncronized
Examples
Attachment a;
a.load(2); // Loads attachment with ID = 2
a.setValue("name", "test.txt");
print(a.getValue("size")); // Size in bytes
load(Integer)
Loads a Service attachment from disk.
Declaration
Bool load(Integer id)
Parameters
Type | Name | Description |
---|---|---|
Integer | id | Attachment ID. |
Returns
Type | Description |
---|---|
Bool | True if the load was successful; otherwise false. |
Examples
Attachment a;
a.load(2); // Loads attachment with ID = 2
a.setValue("name", "test.txt");
print(a.getValue("size")); // Size in bytes
remove()
Deletes the attachment record from the database and the attachment file from disk.
Declaration
remove()
Returns
Type | Description |
---|---|
Examples
Attachment a;
a.load(2); // Loads attachment with ID = 2
a.setValue("name", "test.txt");
print(a.getValue("size")); // Size in bytes
save()
Saves the attachment to disk.
Declaration
Integer save()
Returns
Type | Description |
---|---|
Integer | The attachment ID. |
Examples
Attachment a;
a.load(2); // Loads attachment with ID = 2
a.setValue("name", "test.txt");
print(a.getValue("size")); // Size in bytes
saveBase64(String)
Creates a filename and saves a base64-coded attachment to disk.
Declaration
Integer saveBase64(String attachment)
Parameters
Type | Name | Description |
---|---|---|
String | attachment | The base64-encoded string to save. |
Returns
Type | Description |
---|---|
Integer | The actual number of bytes written to disk. |
Examples
Attachment a;
a.load(2); // Loads attachment with ID = 2
a.setValue("name", "test.txt");
print(a.getValue("size")); // Size in bytes
setValue(String,String)
Sets a value on the attachment object.
Declaration
Void SetValue(String name, String value)
Parameters
Type | Name | Description |
---|---|---|
String | name | The parameter to write. |
String | value | The value to assign to name. |
Returns
Type | Description |
---|---|
Remarks
The current implementation supports the following values as the name parameter.
- id: the attachment ID
- contentType: content descriptor
- name: the filename
- size: size in bytes
- key: authentication key
- charset
- dbiAgentId
- dbiKey
- dbiLastModified
- dbiLastSyncronized
Examples
Attachment a;
a.load(2); // Loads attachment with ID = 2
a.setValue("name", "test.txt");
print(a.getValue("size")); // Size in bytes