gpt4 book ai didi

Firebase 存储 - 限制用户上传到 Firebase 存储的图像大小

转载 作者:行者123 更新时间:2023-12-04 01:31:43 24 4
gpt4 key购买 nike

我是一名新的 Firebase 开发人员。我正在开发一个 android 应用程序,允许用户将图像上传到 firebase 存储。因为我使用的是 Spark 模式,所以我只有 5Gb 的存储空间。
我想限制用户上传到 firebase 存储的图像大小。
下面是我用来将图像上传到 firebase 存储的代码。

Uri imageUri = Uri.parse(imagePath);
//need permistion android.permission.MANAGE_DOCUMENTS to upload file.
final StorageReference photoRef = mStorageRef.child(Constants.FIREBASE_LOCATION_IMAGE_EXAM).child(imageUri.getLastPathSegment());
taskStarted();
photoRef.putFile(imageUri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Log.d(TAG, "upload success");
mUploadExamTaskCount--;
examURLArray.add(new ExamPage(taskSnapshot.getDownloadUrl().toString()));
if (mUploadExamTaskCount == 0) {//upload files success.
/**
* update image link to database.
*/
DatabaseReference firebaseExamPage = FirebaseDatabase.getInstance().getReference(Constants.FIREBASE_LOCATION_EXAM_PAGE);
firebaseExamPage.child(examKey).setValue(examURLArray);
Log.d(TAG, "send upload exam success br");
Intent taskCompletedIntent = new Intent(ACTION_UPLOAD_EXAM_COMPLETED);
LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(taskCompletedIntent);
}
taskCompleted();
}
})

你知道如何解决这个问题吗?

最佳答案

Firebase Storage Security Rules docs ,您可以编写检查上传文件大小的规则:

service firebase.storage {
match /b/<bucket>/o {
match /files/{fileName} {
allow read;
allow write: if request.resource.size < 10 * 1024 * 1024; // 10MB limit for instance
}
}
}

关于Firebase 存储 - 限制用户上传到 Firebase 存储的图像大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38395790/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com