upload method

Future<String?> upload(
  1. AttachmentFile file, {
  2. OnSendProgress? onSendProgress,
  3. CancelToken? cancelToken,
})
  • Upload a File instance or a readable stream of data Usage:
await files.upload(AttachmentFile(path: 'yourfilepath'));
  • To cancel the upload, call token.cancel('cancelled). For example
 var token = CancelToken();
  // In one minute, we cancel!
  Timer(Duration(milliseconds: 500), () {
    token.cancel('cancelled');
  });
  await files.upload(AttachmentFile(path: 'yourfilepath'), token);
  • To get upload progress:
 await files.upload(AttachmentFile(path: 'yourfilepath'), onSendProgress:(sentBytes,totalBytes){
   if (totalBytes != -1) {
      print((sentBytes / total * 100).toStringAsFixed(0) + '%');
    }
 });

API docs: upload

Implementation

Future<String?> upload(
  AttachmentFile file, {
  OnSendProgress? onSendProgress,
  CancelToken? cancelToken,
}) async {
  final token =
      userToken ?? TokenHelper.buildFilesToken(secret!, TokenAction.write);
  return _files.upload(
    token,
    file,
    onSendProgress: onSendProgress,
    cancelToken: cancelToken,
  );
}