Skip to content

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 Content To A Specific File In A Folder
- (void)appendWithFileName:(NSString * _Nonnull)fileName filePath:(NSString * _Nonnull)filePath content:(NSData * _Nonnull)content responseHandler:^(BackendlessFile * _Nonnull)responseHandler errorHandler:^(Fault * _Nonnull)errorHandler;


// Append Content Using A Remote File
- (void)appendWithUrlToFile:(NSString * _Nonnull)urlToFile backendlessPath:(NSString * _Nonnull)backendlessPath responseHandler:^(BackendlessFile * _Nonnull)responseHandler errorHandler:^(Fault * _Nonnull)errorHandler;


// Append Text Converted From The Base64 Encoded String
- (void)appendWithFileName:(NSString * _Nonnull)fileName filePath:(NSString * _Nonnull)filePath base64Content:(NSString * _Nonnull)base64Content responseHandler:^(BackendlessFile * _Nonnull)responseHandler errorHandler:^(Fault * _Nonnull)errorHandler;


// Append Text To A Specific File In A Folder 
- (void)appendWithFileName:(NSString * _Nonnull)fileName filePath:(NSString * _Nonnull)filePath data:(NSString * _Nonnull)data responseHandler:^(BackendlessFile * _Nonnull)responseHandler errorHandler:^(Fault * _Nonnull)errorHandler;
// Append Content To A Specific File In A Folder
func append(fileName: String, filePath: String, content: Data, responseHandler: ((BackendlessFile) -> Void)!, errorHandler: ((Fault) -> Void)!)


// Append Content Using A Remote File
func append(urlToFile: String, backendlessPath: String, responseHandler: ((BackendlessFile) -> Void)!, errorHandler: ((Fault) -> Void)!)


// Append Text Converted From The Base64 Encoded String
func append(fileName: String, filePath: String, base64Content: String, responseHandler: ((BackendlessFile) -> Void)!, errorHandler: ((Fault) -> Void)!)


// Append Text To A Specific File In A Folder
func append(fileName: String, filePath: String, data: String, responseHandler: ((BackendlessFile) -> Void)!, errorHandler: ((Fault) -> Void)!)

where:

Argument                Description
filePath 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.
content String Value. Specify the content to be appended to the file.
base64Content String Value. Identifies the Base64 encoded data that will be decoded and appended as text to the specified file.
backendlessPath String Value. Identifies the full path to the file stored in Backendless where the new content is appended. For instance: "/notes/school/biology.txt".
urlToFile String Value. Represents the URL of the remote file that contains the data to be appended to the file stored in Backendless.
data Represents a string value that must be appended as text to the specified file.
responseHandler Handles successful result of an asynchronous call.
errorHandler Handles fault result of an asynchronous call.

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".

// Append Content To A Specific File In A Folder
- (void)appendWithFileName:(NSString * _Nonnull)fileName filePath:(NSString * _Nonnull)filePath content:(NSData * _Nonnull)content responseHandler:^(BackendlessFile * _Nonnull)responseHandler errorHandler:^(Fault * _Nonnull)errorHandler;


// Append Content Using A Remote File
- (void)appendWithUrlToFile:(NSString * _Nonnull)urlToFile backendlessPath:(NSString * _Nonnull)backendlessPath responseHandler:^(BackendlessFile * _Nonnull)responseHandler errorHandler:^(Fault * _Nonnull)errorHandler;


// Append Text Converted From The Base64 Encoded String
- (void)appendWithFileName:(NSString * _Nonnull)fileName filePath:(NSString * _Nonnull)filePath base64Content:(NSString * _Nonnull)base64Content responseHandler:^(BackendlessFile * _Nonnull)responseHandler errorHandler:^(Fault * _Nonnull)errorHandler;


// Append Text To A Specific File In A Folder 
- (void)appendWithFileName:(NSString * _Nonnull)fileName filePath:(NSString * _Nonnull)filePath data:(NSString * _Nonnull)data responseHandler:^(BackendlessFile * _Nonnull)responseHandler errorHandler:^(Fault * _Nonnull)errorHandler;
// Append Content To A Specific File In A Folder
func append(fileName: String, filePath: String, content: Data, responseHandler: ((BackendlessFile) -> Void)!, errorHandler: ((Fault) -> Void)!)


// Append Content Using A Remote File
func append(urlToFile: String, backendlessPath: String, responseHandler: ((BackendlessFile) -> Void)!, errorHandler: ((Fault) -> Void)!)


// Append Text Converted From The Base64 Encoded String
func append(fileName: String, filePath: String, base64Content: String, responseHandler: ((BackendlessFile) -> Void)!, errorHandler: ((Fault) -> Void)!)


// Append Text To A Specific File In A Folder
func append(fileName: String, filePath: String, data: String, responseHandler: ((BackendlessFile) -> Void)!, errorHandler: ((Fault) -> Void)!)

Appending Base64 encoded data

The example below converts data stored in a byte buffer and appends it to the "textFile.txt" file stored in the "notes/customFolder".

// Append Content To A Specific File In A Folder
- (void)appendWithFileName:(NSString * _Nonnull)fileName filePath:(NSString * _Nonnull)filePath content:(NSData * _Nonnull)content responseHandler:^(BackendlessFile * _Nonnull)responseHandler errorHandler:^(Fault * _Nonnull)errorHandler;


// Append Content Using A Remote File
- (void)appendWithUrlToFile:(NSString * _Nonnull)urlToFile backendlessPath:(NSString * _Nonnull)backendlessPath responseHandler:^(BackendlessFile * _Nonnull)responseHandler errorHandler:^(Fault * _Nonnull)errorHandler;


// Append Text Converted From The Base64 Encoded String
- (void)appendWithFileName:(NSString * _Nonnull)fileName filePath:(NSString * _Nonnull)filePath base64Content:(NSString * _Nonnull)base64Content responseHandler:^(BackendlessFile * _Nonnull)responseHandler errorHandler:^(Fault * _Nonnull)errorHandler;


// Append Text To A Specific File In A Folder 
- (void)appendWithFileName:(NSString * _Nonnull)fileName filePath:(NSString * _Nonnull)filePath data:(NSString * _Nonnull)data responseHandler:^(BackendlessFile * _Nonnull)responseHandler errorHandler:^(Fault * _Nonnull)errorHandler;
// Append Content To A Specific File In A Folder
func append(fileName: String, filePath: String, content: Data, responseHandler: ((BackendlessFile) -> Void)!, errorHandler: ((Fault) -> Void)!)


// Append Content Using A Remote File
func append(urlToFile: String, backendlessPath: String, responseHandler: ((BackendlessFile) -> Void)!, errorHandler: ((Fault) -> Void)!)


// Append Text Converted From The Base64 Encoded String
func append(fileName: String, filePath: String, base64Content: String, responseHandler: ((BackendlessFile) -> Void)!, errorHandler: ((Fault) -> Void)!)


// Append Text To A Specific File In A Folder
func append(fileName: String, filePath: String, data: String, responseHandler: ((BackendlessFile) -> Void)!, errorHandler: ((Fault) -> Void)!)

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"

// Append Content To A Specific File In A Folder
- (void)appendWithFileName:(NSString * _Nonnull)fileName filePath:(NSString * _Nonnull)filePath content:(NSData * _Nonnull)content responseHandler:^(BackendlessFile * _Nonnull)responseHandler errorHandler:^(Fault * _Nonnull)errorHandler;


// Append Content Using A Remote File
- (void)appendWithUrlToFile:(NSString * _Nonnull)urlToFile backendlessPath:(NSString * _Nonnull)backendlessPath responseHandler:^(BackendlessFile * _Nonnull)responseHandler errorHandler:^(Fault * _Nonnull)errorHandler;


// Append Text Converted From The Base64 Encoded String
- (void)appendWithFileName:(NSString * _Nonnull)fileName filePath:(NSString * _Nonnull)filePath base64Content:(NSString * _Nonnull)base64Content responseHandler:^(BackendlessFile * _Nonnull)responseHandler errorHandler:^(Fault * _Nonnull)errorHandler;


// Append Text To A Specific File In A Folder 
- (void)appendWithFileName:(NSString * _Nonnull)fileName filePath:(NSString * _Nonnull)filePath data:(NSString * _Nonnull)data responseHandler:^(BackendlessFile * _Nonnull)responseHandler errorHandler:^(Fault * _Nonnull)errorHandler;
// Append Content To A Specific File In A Folder
func append(fileName: String, filePath: String, content: Data, responseHandler: ((BackendlessFile) -> Void)!, errorHandler: ((Fault) -> Void)!)


// Append Content Using A Remote File
func append(urlToFile: String, backendlessPath: String, responseHandler: ((BackendlessFile) -> Void)!, errorHandler: ((Fault) -> Void)!)


// Append Text Converted From The Base64 Encoded String
func append(fileName: String, filePath: String, base64Content: String, responseHandler: ((BackendlessFile) -> Void)!, errorHandler: ((Fault) -> Void)!)


// Append Text To A Specific File In A Folder
func append(fileName: String, filePath: String, data: String, responseHandler: ((BackendlessFile) -> Void)!, errorHandler: ((Fault) -> Void)!)

Codeless Reference

files_api_append_file_1

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.

Thesource 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:

files_api_append_file_2

This file has the following content:

files_api_append_file_3

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.

files_api_append_file_4

The operation has successfully appended the new text to the file:

files_api_append_file_5

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.

files_api_append_file_6

The result of this operation is shown below:

files_api_append_file_7

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.

files_api_append_file_8

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:

files_api_append_file_9