🐛 Fix web file upload
This commit is contained in:
@@ -147,7 +147,17 @@ void main() async {
|
||||
|
||||
runApp(
|
||||
ProviderScope(
|
||||
observers: [TalkerRiverpodObserver(talker: talker)],
|
||||
observers: [
|
||||
TalkerRiverpodObserver(
|
||||
talker: talker,
|
||||
settings: TalkerRiverpodLoggerSettings(
|
||||
printProviderAdded: false,
|
||||
printProviderDisposed: false,
|
||||
printProviderUpdated: false,
|
||||
printStateFullData: false,
|
||||
),
|
||||
),
|
||||
],
|
||||
overrides: [sharedPreferencesProvider.overrideWithValue(prefs)],
|
||||
child: Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
|
@@ -106,6 +106,7 @@ final apiClientProvider = Provider<Dio>((ref) {
|
||||
printResponseHeaders: false,
|
||||
printResponseMessage: false,
|
||||
printRequestData: false,
|
||||
printResponseData: false,
|
||||
),
|
||||
),
|
||||
]);
|
||||
|
@@ -1,5 +1,4 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'dart:ui';
|
||||
import 'package:croppy/croppy.dart';
|
||||
import 'package:cross_file/cross_file.dart';
|
||||
@@ -9,7 +8,6 @@ import 'package:flutter/widgets.dart';
|
||||
import 'package:island/models/file.dart';
|
||||
import 'package:island/services/file_uploader.dart';
|
||||
import 'package:native_exif/native_exif.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
enum FileUploadMode { generic, mediaSafe }
|
||||
|
||||
@@ -21,8 +19,7 @@ Future<XFile?> cropImage(
|
||||
}) async {
|
||||
final result = await showMaterialImageCropper(
|
||||
context,
|
||||
imageProvider:
|
||||
kIsWeb ? NetworkImage(image.path) : FileImage(File(image.path)),
|
||||
imageProvider: MemoryImage(await image.readAsBytes()),
|
||||
showLoadingIndicatorOnSubmit: true,
|
||||
allowedAspectRatios: allowedAspectRatios,
|
||||
);
|
||||
@@ -64,7 +61,10 @@ Completer<SnCloudFile?> putFileToCloud({
|
||||
fileData.isOnDevice &&
|
||||
fileData.type == UniversalFileType.image) {
|
||||
final data = fileData.data;
|
||||
if (data is XFile && !kIsWeb && (Platform.isIOS || Platform.isAndroid)) {
|
||||
if (data is XFile &&
|
||||
!kIsWeb &&
|
||||
(defaultTargetPlatform == TargetPlatform.iOS ||
|
||||
defaultTargetPlatform == TargetPlatform.android)) {
|
||||
Exif.fromPath(data.path)
|
||||
.then((exif) async {
|
||||
final gpsAttributes = {
|
||||
@@ -184,15 +184,11 @@ Completer<SnCloudFile?> _processUpload(
|
||||
|
||||
final uploader = FileUploader(dio);
|
||||
|
||||
// Get File object
|
||||
File fileObj;
|
||||
if (file.path.isNotEmpty) {
|
||||
fileObj = File(file.path);
|
||||
// Call progress start
|
||||
onProgress?.call(0.0, Duration.zero);
|
||||
uploader
|
||||
.uploadFile(
|
||||
file: fileObj,
|
||||
file: file,
|
||||
fileName: actualFilename,
|
||||
contentType: actualMimetype,
|
||||
poolId: poolId,
|
||||
@@ -206,45 +202,6 @@ Completer<SnCloudFile?> _processUpload(
|
||||
completer.completeError(e);
|
||||
throw e;
|
||||
});
|
||||
} else {
|
||||
// Write to temp file
|
||||
getTemporaryDirectory()
|
||||
.then((tempDir) {
|
||||
final tempFile = File('${tempDir.path}/temp_upload_$actualFilename');
|
||||
file
|
||||
.readAsBytes()
|
||||
.then((bytes) => tempFile.writeAsBytes(bytes))
|
||||
.then((_) {
|
||||
fileObj = tempFile;
|
||||
// Call progress start
|
||||
onProgress?.call(0.0, Duration.zero);
|
||||
uploader
|
||||
.uploadFile(
|
||||
file: fileObj,
|
||||
fileName: actualFilename,
|
||||
contentType: actualMimetype,
|
||||
poolId: poolId,
|
||||
)
|
||||
.then((result) {
|
||||
// Call progress end
|
||||
onProgress?.call(1.0, Duration.zero);
|
||||
completer.complete(result);
|
||||
})
|
||||
.catchError((e) {
|
||||
completer.completeError(e);
|
||||
throw e;
|
||||
});
|
||||
})
|
||||
.catchError((e) {
|
||||
completer.completeError(e);
|
||||
throw e;
|
||||
});
|
||||
})
|
||||
.catchError((e) {
|
||||
completer.completeError(e);
|
||||
throw e;
|
||||
});
|
||||
}
|
||||
|
||||
return completer;
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:cross_file/cross_file.dart';
|
||||
import 'package:crypto/crypto.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
@@ -14,7 +14,7 @@ class FileUploader {
|
||||
FileUploader(this._dio);
|
||||
|
||||
/// Calculates the MD5 hash of a file.
|
||||
Future<String> _calculateFileHash(File file) async {
|
||||
Future<String> _calculateFileHash(XFile file) async {
|
||||
final bytes = await file.readAsBytes();
|
||||
final digest = md5.convert(bytes);
|
||||
return digest.toString();
|
||||
@@ -22,7 +22,7 @@ class FileUploader {
|
||||
|
||||
/// Creates an upload task for the given file.
|
||||
Future<Map<String, dynamic>> createUploadTask({
|
||||
required File file,
|
||||
required XFile file,
|
||||
required String fileName,
|
||||
required String contentType,
|
||||
String? poolId,
|
||||
@@ -80,7 +80,7 @@ class FileUploader {
|
||||
|
||||
/// Uploads a file in chunks using the multi-part API.
|
||||
Future<SnCloudFile> uploadFile({
|
||||
required File file,
|
||||
required XFile file,
|
||||
required String fileName,
|
||||
required String contentType,
|
||||
String? poolId,
|
||||
|
Reference in New Issue
Block a user