我正在使用Flutter开发一款Android应用。在我的应用程序中,有一个功能,用户可以从其设备上传图片。为了存储图片,我正在使用Firebase云存储,以下是我用来上传文件到Firebase云存储的代码部分。
String fileName = "${this.userDetails['id']}_${uuid.v1()}";
String fileExtension = p.extension(_imageFile.path);
String newFileName = p.setExtension(fileName, fileExtension);
print("STEP 1: New filename of image - 111: $newFileName");
final StorageReference ref = FirebaseStorage.instance.ref().child("images/users/original/$newFileName");
final StorageUploadTask uploadTask = ref.put(
_imageFile, const StorageMetadata(contentLanguage: "en")
);
print("STEP 2: Image file uploaded - 222");
final Uri downloadUrl = (await uploadTask.future).downloadUrl;
print('STEP 3: downloadUrl data received - 333 : $downloadUrl');
final http.Response downloadData = await http.get(downloadUrl);
print('STEP 4: Download data received - 444 : ${downloadData.body}');
这里有3个相关的Flutter插件,它们帮助上述代码上传文件。
import 'package:uuid/uuid.dart';
import 'package:path/path.dart' as p;
import 'package:firebase_storage/firebase_storage.dart';
一切都运作正常,除了文件上传需要很长时间。几乎需要40-50秒才能完成STEP-3(print('STEP 3: downloadUrl data received - 333 : $downloadUrl');
)。有时也需要1分半钟左右。关于我的网络速度,它的上传和下载速度几乎都是80Mbps。我的平均上传图片大小为100kB。
需要一些帮助来找出问题所在。
添加一个来自我的Android Studio日志的截图(文件大小为2.8 MB) -
I/flutter ( 4451): cliked on image upload button
I/flutter ( 4451): Loading animation started
I/flutter ( 4451): 2018-06-06 23:15:30.327722 - STEP 1: New file name got - 111: KyvU5PFfLRPxYFwHaiKHuywilMV2_679b9ee0-4800-11e8-fe1b-7f6c98d5147d.png
I/flutter ( 4451): 2018-06-06 23:15:30.329420 - STEP 2: Image file uploaded - 222
W/DynamiteModule( 4451): Local module descriptor class for com.google.android.gms.firebasestorage not found.
W/zygote64( 4451): Unsupported class loader
W/zygote64( 4451): Skipping duplicate class check due to unsupported classloader
I/DynamiteModule( 4451): Considering local module com.google.android.gms.firebasestorage:0 and remote module com.google.android.gms.firebasestorage:6
I/DynamiteModule( 4451): Selected remote version of com.google.android.gms.firebasestorage, version >= 6
W/zygote64( 4451): Unsupported class loader
W/zygote64( 4451): Skipping duplicate class check due to unsupported classloader
I/FlutterActivityDelegate( 4451): onResume setting current activity to this
D/UploadTask( 4451): Increasing chunk size to 524288
D/UploadTask( 4451): Increasing chunk size to 1048576
D/UploadTask( 4451): Increasing chunk size to 2097152
I/flutter ( 4451): 2018-06-06 23:17:43.445542 - STEP 3: downloadUrl image data - 333 :
I/flutter ( 4451): 2018-06-06 23:17:46.757227 - STEP 4: Download data - 444 : ÿØÿá1(Exif
注意: 这可能是一个插件问题,因此在 Github 上提交了一个问题
2018-06-06 23:15:30.327722 - 步骤1,2018-06-06 23:15:30.329420 - 步骤2,2018-06-06 23:17:43.445542 - 步骤3,2018-06-06 23:17:46.757227 - 步骤4
。 我在帖子中附上了我的Android Studio的完整截图,也许这会有所帮助。 - Suresh2018-06-07 21:53:01.365738 - 步骤1,2018-06-07 21:53:01.367466 - 步骤2,2018-06-07 21:55:14.857864 - 步骤3,2018-06-07 21:55:22.790003 - 步骤4
。 - Suresh