upload method
Future<String?>
upload(
- AttachmentFile image, {
- OnSendProgress? onSendProgress,
- CancelToken? cancelToken,
Uploading an image
input is a MultipartFile
Example
final file = AttachmentFile(path: 'yourfilepath');
await client.images.upload(multipartFile);
- 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 images.upload(AttachmentFile(path: 'yourfilepath'), token);
- To get upload progress:
await images.upload(AttachmentFile(path: 'yourfilepath'), onSendProgress:(sentBytes,totalBytes){
if (totalBytes != -1) {
print((sentBytes / total * 100).toStringAsFixed(0) + '%');
}
});
API docs: https://getstream.io/activity-feeds/docs/flutter-dart/files_introduction/?q=Image
Implementation
Future<String?> upload(
AttachmentFile image, {
OnSendProgress? onSendProgress,
CancelToken? cancelToken,
}) {
final token =
userToken ?? TokenHelper.buildFilesToken(secret!, TokenAction.write);
return _images.upload(token, image,
onSendProgress: onSendProgress, cancelToken: cancelToken);
}