Firebase 在Flitter中上传到firestore时,有没有办法限制视频文件的大小?
我可以添加一些代码,这样上传者就不会超过视频大小限制吗Firebase 在Flitter中上传到firestore时,有没有办法限制视频文件的大小?,firebase,flutter,dart,firebase-storage,Firebase,Flutter,Dart,Firebase Storage,我可以添加一些代码,这样上传者就不会超过视频大小限制吗 final file = await ImagePicker.pickVideo(source: ImageSource.gallery); StorageReference ref = FirebaseStorage.instance.ref().child("video").child(id); StorageUploadTask uploadTask = ref.p
final file = await ImagePicker.pickVideo(source: ImageSource.gallery);
StorageReference ref = FirebaseStorage.instance.ref().child("video").child(id);
StorageUploadTask uploadTask = ref.putFile(file, StorageMetadata(contentType: 'video/mp4'));
var storageTaskSnapshot = await uploadTask.onComplete;
var downloadUrl = await storageTaskSnapshot.ref.getDownloadURL();
final String url = downloadUrl.toString();
fb.child(id).set({
"id": id,
"link": url,
}).then((value) {
print("Done");
});
});
} catch (error) {
print(error);
}
}
您可以在上载之前检查文件大小:
final filesizeLimit = 999999; // in bytes
final filesize = await file.length(); // in bytes
final isValidFilesize = filesize < filesizeLimit;
if (isValidFilesize) {
// upload...
} else {
// show message to the user that the file is too big
}
final filesizeLimit=999999;//以字节为单位
final filesize=wait file.length();//以字节为单位
最终isValidFilesize=filesize
999999是以字节为单位的,对吗?是的,以字节为单位。谢谢。你能在上传之前帮我编一个压缩文件的代码吗?很抱歉,我没有用颤振/飞镖压缩文件的经验。希望其他人能为你指出正确的方向。好的。非常感谢。您没有上载到Firestore,而是上载到Firebase存储。虽然这两种产品都是Firebase的一部分,但它们是完全独立的。我更新了你问题的标签