I've used a Pyrebase client w/o service-account-key and Rules to upload and access a files on FB Storage, and it worked fine. But now I'm using a google.cloud.storage.Client() with user creds like this:
def readAva(dictCred): #creds dictionary
cred = Credentials(dictCred["user"]["stsTokenManager"]['accessToken'])
stor = storage.Client(project='fbtest-XXX', credentials=cred)
print("CREDs OK")
fName = dictCred["user"]["uid"] + ".png"
url = stor.get_bucket("fbtest-XXX.appspot.com").blob(f"test-users/{fName}").public_url
print("URL=" + url)
return url
and it returns:
127.0.0.1 - - [12/Jul/2023 16:54:18] "GET /DAhmgc5UEFUstSeDjSaAAQ0PUPl1 HTTP/1.1" 200 -
CREDs OK
Can't read an avatar!
Code on Flask:
def userPage(userid):
avaURL = ""
if request.method == "GET":
#if userid != session["userid"]: pageNotFound(404)
#else:
try:
avaURL = storage.readAva(session["dictCred"])
except:
print("Can't read an avatar!")
return render_template("home.html", avaURL=avaURL)
Credentials are OK, they work well with firestore.Client(). Browser console shows no error, but img src="".
Tryed to use a litheral like this: url = stor.get_bucket("fbtest-ba697.appspot.com").blob("test-users/DAhmgc5UEFUstSeDjSaAAQ0PUPl1.png").public_url
-still nothing.
Rules are just:
service firebase.storage {
match /b/{bucket}/o {
match /test-users/{filename} {
allow read: if request.auth != null;
}
}
}
And simulated GET works. Files are present in "test-users" folder.