Hello,
I’m working on getting Firebase Storage to work. If I use your example code for uploading and displaying a photo taken with the CameraPicker, everything uploads fine but I get the following error when the app tries to retrieve the image and display it (everything in <> are actual values I set as <>).
QML AppImage: Error transferring https://firebasestorage.googleapis.com/v0/b/<app_id>.appspot.com/o/users/<user_id>/test-image1575638873178.png?alt=media&token=<token> – server replied: Bad Request
I can log into my online Firebase console and see the the image in the correct location.
Here’s my code:
AppButton {
text: "Capture image + upload"
onClicked: nativeUtils.displayCameraPicker()
}
AppText {
id: status
text: "Idle"
}
// this will display the image after it's uploaded
AppImage {
id: img
width: parent.width
fillMode: AppImage.PreserveAspectFit
autoTransform: true
}
Connections {
target: nativeUtils
onCameraPickerFinished: {
if(accepted) {
var remote_path = "users/" + dataModel.user_id + "/test-image" + Date.now() + ".png"
fbStorage.uploadFile(path, remote_path, function(progress, finished, success, downloadUrl) {
if(!finished) {
status.text = "Uploading... " + progress.toFixed(2) + "%"
} else if(success) {
img.source = downloadUrl
status.text = "Upload completed."
} else {
status.text = "Upload failed."
}
})
}
}
}
FirebaseStorage {
id: fbStorage
config: FirebaseConfig {
id: fbConfig
projectId: "<app_id>"
databaseUrl: "https://<app_id>.firebaseio.com"
storageBucket: "<app_id>.appspot.com"
apiKey: Qt.platform.os === "android"
? "<android_key>"
: "<ios_key>"
applicationId: Qt.platform.os === "android"
? "<android_id>"
: "<ios_id>"
}
}
I can’t find anything online about this issue but it seems to be related to user authentication as if I set the Firebase storage rules to be public, the photo displays as it should, but once I change it to require user authentication, I get the error. My Firebase storage bucket rules are:
service firebase.storage {
match /b/{bucket}/o {
match /users/{userId}/{allPaths=**} {
allow read, write: if request.auth.uid == userId;
}
}
}
Again, everything writes to the bucket correctly, it just won’t download the image.
Any help would be appreciated.
Thank you,
Eric