Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OnComplete bug #17

Open
AmirHosseinBaderan opened this issue Nov 15, 2024 · 0 comments
Open

OnComplete bug #17

AmirHosseinBaderan opened this issue Nov 15, 2024 · 0 comments

Comments

@AmirHosseinBaderan
Copy link

OnComplete not invoke

   When files upload to server OnComplete event not invoke 
   but server saved the file and return download link 

this is my code implementation

import 'package:tus_client_dart/tus_client_dart.dart';
  
Future<void> uploadFile(
      {required XFile file,
      Function(TusClient client)? onComplete,
      Function(double)? onProgress}) async {
    try {
      final completer = Completer<void>();
      final token = await login();
      if (token.isNotEmpty) {
        final uri = Uri.parse('${Links.tusBaseUrl}/${Links.tusUrl}');

        //? Create file store
        final tempDir = await getTemporaryDirectory();
        final tempDirectory = Directory('${tempDir.path}/${file.name}_uploads');
        if (!tempDirectory.existsSync()) {
          tempDirectory.createSync(recursive: true);
        }

        final client = TusClient(
          file,
          store: TusFileStore(tempDirectory),
        );
        await client.upload(
          uri: uri,
          measureUploadSpeed: true,
          headers: {
            TusClientVariables.authToken:
                TusClientVariables.authTokenVal(token),
          },
          onStart: (client, duration) {},
          onProgress: (value, duration) async {
            if (onProgress != null) onProgress(value);
            if (value == 100) {
              if (onComplete != null) onComplete(client);
              completer.complete();
              return;
            }
          },
          onComplete: () {
            print("Completed!");
            tempDirectory.deleteSync(recursive: true);
          },
        );
        return;
      }
    } catch (e) {
      print(e);
      return;
    }
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant