Well, there’s a very easy way to do it, and there’s the right way to do it.
- : users/{userid}/0.jpg users/{userid}/9.jpg ( 10 ).
, :
match /users/{userId}/{photoId} {
allow write: if photoId.matches('^\d\.jpg$')
}
, - :
match /users/{userId}/{photoId} {
allow write: if int(photoId.split('\.')[0]) < XXX
}
: , , ? , , - ( ) . :
// Allow files to be overwritten once a day, written if there nothing there, or deleted as often as desired
match /users/{userId}/{photoId} {
allow write: if request.time > resource.timeCreated + duration.value(1, "d") || resource.size == 0 || request.resource.size == 0
}
:
function isAllowedPhotoId(photoId) {
return int(photoId.split('\.')[0]) < XXX
}
function canOverwritePhoto() {
return request.time > resource.timeCreated + duration.value(1, "d") || resource.size == 0 || request.resource.size == 0
}
match /users/{userId}/{photoId} {
allow write: if isAllowedPhotoId(photoId) && canOverwritePhoto()
}
Storage . , , .