append method

Future<String> append(
  1. String filePath,
  2. String fileName, {
  3. String? base64Content,
  4. String? urlToFile,
  5. String? dataContent,
})

This method adds data to the content of your file from one of the key parameters. You need to specify only one of the key parameters: base64Content, urlToFile, dataContent. If more than one of the key parameters is specified. Only one of the specifications will be executed. The priority looks like this:

  1. base64Content - take file and decode from base64 like for saveFile method.
  2. urlToFile - take file from URL like in upload method.
  3. dataContent - take body as is and append to file.

Implementation

Future<String> append(String filePath, String fileName,
    {String? base64Content, String? urlToFile, String? dataContent}) async {
  if (base64Content?.isNotEmpty ?? false) {
    String methodName = '/files/append/binary/$filePath/$fileName';
    var headers = <String, String>{
      'Content-Type': 'text/plain',
    };

    return await Invoker.put(methodName, base64Content,
        customHeaders: headers);
  }

  if (urlToFile?.isNotEmpty ?? false) {
    String methodName = '/files/append/$filePath/$fileName';
    var parameters = <String, String>{'url': urlToFile!};

    return await Invoker.post(methodName, parameters);
  }

  if (dataContent?.isNotEmpty ?? false) {
    String methodName = '/files/append/$filePath/$fileName';
    var headers = <String, String>{
      'Content-Type': 'text/plain',
    };

    return await Invoker.put(methodName, dataContent, customHeaders: headers);
  }

  throw ArgumentError(
      "${ExceptionMessage.noOneKeyArgumentSpecified}: 'base64Content', 'urlToFile' or 'dataContent'");
}