Line data Source code
1 : import 'package:dio/dio.dart'; 2 : import 'package:stream_feed_dart/src/core/api/files_api.dart'; 3 : import 'package:stream_feed_dart/src/core/http/token.dart'; 4 : import 'package:stream_feed_dart/src/core/util/token_helper.dart'; 5 : 6 : class FileStorageClient { 7 2 : FileStorageClient(this.files, {this.userToken, this.secret}) 8 : : assert( 9 0 : userToken != null || secret != null, 10 : 'At least a secret or userToken must be provided', 11 : ); 12 : final String? secret; 13 : final Token? userToken; 14 : final FilesApi files; 15 : 16 : /// Upload a File instance or a readable stream of data 17 : /// Usage: 18 : /// ```dart 19 : /// final file = File('yourfilepath'); 20 : /// var multipartFile = await MultipartFile.fromFile( 21 : /// file.path, 22 : /// filename: 'my-file' 23 : /// ); 24 : /// await images.upload(multipartFile); 25 : /// ``` 26 : /// API docs: [upload](https://getstream.io/activity-feeds/docs/flutter-dart/files_introduction/?language=dart#upload) 27 1 : Future<String?> upload(MultipartFile file) { 28 : final token = 29 1 : userToken ?? TokenHelper.buildFilesToken(secret!, TokenAction.write); 30 2 : return files.upload(token, file); 31 : } 32 : 33 : /// Delete a file using the url returned by the APIs 34 : /// /// Usage: 35 : /// ```dart 36 : /// await files.delete('fileUrl'); 37 : /// ``` 38 : /// 39 : /// Parameters: 40 : /// - [url] : the url of the file you want to delete 41 : /// API docs: [delete](https://getstream.io/activity-feeds/docs/flutter-dart/files_introduction/?language=dart#delete) 42 1 : Future<void> delete(String url) { 43 : final token = 44 1 : userToken ?? TokenHelper.buildFilesToken(secret!, TokenAction.delete); 45 2 : return files.delete(token, url); 46 : } 47 : }