TF-2245 Fix upload attachment when token expired on web
Signed-off-by: dab246 <tdvu@linagora.com> (cherry picked from commit 0b2ab3c6ff4213bccc064822e640cc40592a39e8)
This commit is contained in:
@@ -1750,17 +1750,17 @@ class ComposerController extends BaseController {
|
||||
|
||||
Future<InlineImage?> _selectFromFile() async {
|
||||
final filePickerResult = await FilePicker.platform.pickFiles(
|
||||
type: FileType.image,
|
||||
withData: PlatformInfo.isMobile,
|
||||
withReadStream: PlatformInfo.isWeb);
|
||||
final platformFile = filePickerResult?.files.single;
|
||||
if (platformFile != null) {
|
||||
type: FileType.image,
|
||||
withData: PlatformInfo.isWeb
|
||||
);
|
||||
if (filePickerResult?.files.isNotEmpty == true) {
|
||||
PlatformFile platformFile = filePickerResult!.files.first;
|
||||
final fileSelected = FileInfo(
|
||||
platformFile.name,
|
||||
PlatformInfo.isWeb ? '' : platformFile.path ?? '',
|
||||
platformFile.size,
|
||||
bytes: platformFile.bytes,
|
||||
readStream: platformFile.readStream);
|
||||
platformFile.name,
|
||||
PlatformInfo.isWeb ? '' : platformFile.path ?? '',
|
||||
platformFile.size,
|
||||
bytes: PlatformInfo.isWeb ? platformFile.bytes : null,
|
||||
);
|
||||
return InlineImage(ImageSource.local, fileInfo: fileSelected);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ import 'dart:convert' as convert;
|
||||
import 'dart:typed_data' as type_data;
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:get/get_connect/http/src/request/request.dart';
|
||||
import 'package:html_editor_enhanced/utils/file_upload_model.dart';
|
||||
import 'package:model/upload/file_info.dart';
|
||||
|
||||
@@ -26,9 +25,9 @@ extension FileUploadExtension on FileUpload {
|
||||
|
||||
Future<FileInfo?> toFileInfo() async {
|
||||
if (base64Data != null) {
|
||||
final bytesStream = await compute(convertBytesToStream, base64Data!);
|
||||
return FileInfo.fromStream(
|
||||
stream: bytesStream,
|
||||
final bytes = await compute(convertBase64ToBytes, base64Data!);
|
||||
return FileInfo.fromBytes(
|
||||
bytes: bytes,
|
||||
name: name,
|
||||
size: size
|
||||
);
|
||||
@@ -37,9 +36,8 @@ extension FileUploadExtension on FileUpload {
|
||||
}
|
||||
}
|
||||
|
||||
static Stream<List<int>> convertBytesToStream(String base64) {
|
||||
static Uint8List convertBase64ToBytes(String base64) {
|
||||
type_data.Uint8List decodeBytes = convert.base64Decode(base64);
|
||||
final bytesStream = BodyBytesStream.fromBytes(decodeBytes);
|
||||
return bytesStream;
|
||||
return decodeBytes;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user