UploadTask.fromFile constructor

UploadTask.fromFile({
  1. required File file,
  2. String? taskId,
  3. required String url,
  4. Map<String, String>? urlQueryParameters,
  5. Map<String, String>? headers,
  6. String? httpRequestMethod,
  7. String? post,
  8. String fileField = 'file',
  9. String? mimeType,
  10. Map<String, String>? fields,
  11. String group = 'default',
  12. Updates updates = Updates.status,
  13. bool requiresWiFi = false,
  14. int retries = 0,
  15. int priority = 5,
  16. String metaData = '',
  17. String displayName = '',
  18. DateTime? creationTime,
})

Creates UploadTask from a File object, using the file absolute path.

Note that using absolute paths is discouraged on mobile, as the path to files in an application's directory scope is not stable between application starts. Use the combination of baseDirectory, directory and filename whenever possible to prevent hard to debug errors.

Implementation

UploadTask.fromFile(
    {required File file,
    super.taskId,
    required super.url,
    super.urlQueryParameters,
    super.headers,
    String? httpRequestMethod,
    String? super.post,
    this.fileField = 'file',
    String? mimeType,
    Map<String, String>? fields,
    super.group,
    super.updates,
    super.requiresWiFi,
    super.retries,
    super.priority,
    super.metaData,
    super.displayName,
    super.creationTime})
    : fields = fields ?? {},
      mimeType =
          mimeType ?? lookupMimeType(file.path) ?? 'application/octet-stream',
      super(
          baseDirectory: BaseDirectory.root,
          directory: p.dirname(file.absolute.path),
          filename: p.basename(file.absolute.path),
          httpRequestMethod: httpRequestMethod ?? 'POST',
          allowPause: false);