fix: minor

This commit is contained in:
Salvatore Giordano
2021-03-03 12:47:19 +01:00
parent 529995164d
commit b28ae12597
8 changed files with 114 additions and 77 deletions
@@ -277,6 +277,7 @@ class Channel {
);
}
}).catchError((e, stk) {
client.logger.severe('error uploading the attachment', e, stk);
updateAttachment(
it.copyWith(uploadState: UploadState.failed(error: e.toString())),
);
@@ -70,16 +70,28 @@ class StreamAttachmentFileUploader implements AttachmentFileUploader {
ProgressCallback onSendProgress,
CancelToken cancelToken,
}) async {
final filename = file.path?.split('/')?.last;
final filename = file.path?.split('/')?.last ?? file.name;
final mimeType = filename.mimeType;
MultipartFile multiPartFile;
if (file.path != null) {
multiPartFile = await MultipartFile.fromFile(
file.path,
filename: filename,
contentType: mimeType,
);
} else if (file.bytes != null) {
multiPartFile = MultipartFile.fromBytes(
file.bytes,
filename: filename,
contentType: mimeType,
);
}
final response = await _client.post(
'/channels/$channelType/$channelId/image',
data: FormData.fromMap({
'file': await MultipartFile.fromFile(
file.path,
filename: filename,
contentType: mimeType,
),
'file': multiPartFile,
}),
onSendProgress: onSendProgress,
cancelToken: cancelToken,
@@ -95,16 +107,28 @@ class StreamAttachmentFileUploader implements AttachmentFileUploader {
ProgressCallback onSendProgress,
CancelToken cancelToken,
}) async {
final filename = file.path?.split('/')?.last;
final filename = file.path?.split('/')?.last ?? file.name;
final mimeType = filename.mimeType;
MultipartFile multiPartFile;
if (file.path != null) {
multiPartFile = await MultipartFile.fromFile(
file.path,
filename: filename,
contentType: mimeType,
);
} else if (file.bytes != null) {
multiPartFile = MultipartFile.fromBytes(
file.bytes,
filename: filename,
contentType: mimeType,
);
}
final response = await _client.post(
'/channels/$channelType/$channelId/file',
data: FormData.fromMap({
'file': await MultipartFile.fromFile(
file.path,
filename: filename,
contentType: mimeType,
),
'file': multiPartFile,
}),
onSendProgress: onSendProgress,
cancelToken: cancelToken,