createFile method

Future<File> createFile({
  1. required String bucketId,
  2. required String fileId,
  3. required InputFile file,
  4. List<String>? permissions,
  5. dynamic onProgress(
    1. UploadProgress
    )?,
})

Create File

Create a new file. Before using this route, you should create a new bucket resource using either a server integration API or directly from your Appwrite console.

Larger files should be uploaded using multiple requests with the content-range header to send a partial request with a maximum supported chunk of 5MB. The content-range header values should always be in bytes.

When the first request is sent, the server will return the File object, and the subsequent part request must include the file's id in x-appwrite-id header to allow the server to know that the partial upload is for the existing file and not for a new one.

If you're creating a new file using one of the Appwrite SDKs, all the chunking logic will be managed by the SDK internally.

Implementation

Future<models.File> createFile(
    {required String bucketId,
    required String fileId,
    required InputFile file,
    List<String>? permissions,
    Function(UploadProgress)? onProgress}) async {
  final String path =
      '/storage/buckets/{bucketId}/files'.replaceAll('{bucketId}', bucketId);

  final Map<String, dynamic> params = {
    'fileId': fileId,
    'file': file,
    'permissions': permissions,
  };

  final Map<String, String> headers = {
    'content-type': 'multipart/form-data',
  };

  String idParamName = '';
  idParamName = 'fileId';
  final paramName = 'file';
  final res = await client.chunkedUpload(
    path: path,
    params: params,
    paramName: paramName,
    idParamName: idParamName,
    headers: headers,
    onProgress: onProgress,
  );

  return models.File.fromMap(res.data);
}