Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firebase 在Flitter中上传到firestore时,有没有办法限制视频文件的大小?_Firebase_Flutter_Dart_Firebase Storage - Fatal编程技术网

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的一部分,但它们是完全独立的。我更新了你问题的标签