Append Data To File¶
The Append
operation allows adding new content to the end of an existing file. The operation writes new data to the file without overwriting the existing content.
Method¶
// Append Text To A File
function appendText(directoryPath: string, fileName: string, fileContent: string): Promise<string>;
function appendText(filePath: string, fileContent: string): Promise<string>;
// Append Text Converted From Bytes
function append(filePath: string, fileContent: Blob | Buffer | ArrayBuffer | number[]): Promise<string>;
function append(directoryPath: string, fileName: string, fileContent: Blob | Buffer | ArrayBuffer | number[]): Promise<string>;
// Append Content From The Remote File Using URL
function append(filePath: string, fileURL: string): Promise<string>;
function append(directoryPath: string, fileName: string, fileURL: string): Promise<string>;
where:
Argument | Description |
---|---|
directoryPath |
String Value. Specify the path to the Backendless directory where the file to be appended with data is stored. |
fileName |
String Value. Specify the name of the file to be appended with data. |
fileContent |
String Value. Specify the content to be appended to the file. |
filePath |
String Value. Identifies the full path to the file stored in Backendless where the new content is appended. For instance: "/notes/school/biology.txt" . |
fileURL |
String Value. Represents the URL of the remote file that contains the data to be appended to the file stored in Backendless. |
Return Value¶
The URL containing the path to the file with the newly appended content. This URL can be used to download the file directly from Backendless.
Example¶
Append text to file
The example below appends the text "``The quick brown fox jumps over the lazy dog``"
to the "testFile.txt"
located in the "notes/customFolder"
.
// Example 1
await Backendless.Files.appendText('notes/customFolder', 'testFile.txt', 'The quick brown fox jumps over the lazy dog')
// Example 2
await Backendless.Files.appendText('notes/customFolder/testFile.txt', 'The quick brown fox jumps over the lazy dog')
Appending bytes
The example below converts data stored in a byte buffer and appends it to the "textFile.txt"
file stored in the "notes/customFolder"
.
// You must implement your own way to write bytes to the buffer,
// so that you could use it in the invocation.
const buffer = new ArrayBuffer(8);
const view = new Int32Array(buffer);
// Example 1
await Backendless.Files.append('notes/customFolder/textFile.txt', view)
// Example 2
await Backendless.Files.append('notes/customFolder', 'textFile.txt', view)
Append content from a remote file
The example below uses the contents of the remote file and appends it to the "textFile.txt"
file stored in the "notes/customFolder"
folder. The URL to the remote file is represented as: "https://xxxx.backendless.app/api/files/notes/grocery/products.txt"
const url = "https://xxxx.backendless.app/api/files/notes/grocery/products.txt";
// Example 1
await Backendless.Files.append('customFolder/textFile.txt', url)
// Example 2
await Backendless.Files.append('customFolder', 'textFile.txt', url)
Codeless Reference¶
where:
Argument | Description |
---|---|
file path |
A path for a file stored in Backendless. The new content will be appended to this file. The path must start with a forward slash "/" identifying the root directory. |
text / source URL / bytes |
When text is selected, this Codeless block is instructed to append a string value to the specified file stored in Backendless. The source URL option identifies location of a remote file to append the content of. When this option is selected, the Codeless block uses the content of the remote file and appends it to the file stored in Backendless. The bytes option identifies the binary data. By selecting this option, you instruct the Codeless block to expect bytes that will be decoded and appended to the file stored in Backendless. |
return URL of the file |
When this checkbox is selected, the operation will return the URL to the file where the new data was appended. |
Returns a URL containing the path to the file with the newly appended content. This URL can be used to download the file directly from Backendless.
Consider a text file stored in Backendless:
This file has the following content:
Appending text to file
The example below appends the "5. lettuce"
text to the file. Note that the file is stored in the "/notes/grocery"
folder.
The operation has successfully appended the new text to the file:
Appending bytes to file
The example below converts the string value " 5. Carrots"
from text to bytes and appends it to the "dinner.txt"
file stored in the "/notes/grocery/"
directory. Note that you must use the "Convert data"
Codeless block in order to convert text
to bytes.
The result of this operation is shown below:
Append content from a remote file
The example below uses the contents of the remote file and appends it to the "dinner.txt"
file stored in the "/notes/grocery"
folder.
The result of this operation is shown below, as you can see a new string ( " 5. Strawberry"
) value was appended to the end of the file: