I am trying to access firebase storage from a custom action. I am getting this error "Firebase Storage: User does not have permission to access 'images/1700597296855.jpg"
This is the firebase storage rules
I set it to be managed from outside in flutterflow
This is the custom action
// Automatic FlutterFlow imports
import '/backend/backend.dart';
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/actions/index.dart'; // Imports other custom actions
import '/flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';
// Begin custom action code
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!
import 'package:http/http.dart' as http;
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_storage/firebase_storage.dart';
import 'package:firebase_auth/firebase_auth.dart';
// Set your action name, define your arguments and return parameter,
// and then add the boilerplate code using the green button on the right!
Future<String> uploadImageAndReturnURL(String tempImageUrl) async {
try {
// Fetch image data from t Failed running flutter pub get...he URL
final http.Response response = await http.get(Uri.parse(tempImageUrl));
List<int> imageData = response.bodyBytes;
// Create a unique filename for the image in Firebase Storage
final String filename = DateTime.now().millisecondsSinceEpoch.toString();
final Reference storageReference =
FirebaseStorage.instance.ref().child('images/$filename.jpg');
Uint8List imageDataUint8List = Uint8List.fromList(imageData);
// Upload the image to Firebase Storage
await storageReference.putData(
imageDataUint8List, SettableMetadata(contentType: 'image/jpeg'));
// Get the download URL of the uploaded image
final String downloadURL = await storageReference.getDownloadURL();
// Store the download URL in Firestore
await FirebaseFirestore.instance.collection('temporaryImage').add({
'imageUrl': downloadURL,
'timestamp': FieldValue.serverTimestamp(),
});
// Return the download URL
return downloadURL;
} catch (error) {
print('Error uploading image: $error');
final user = FirebaseAuth.instance.currentUser;
if (user != null) {
print('User ID: ${user.uid}');
} else {
print('User is not signed in.');
}
return '';
}
}
It prints the user id that is logging in and I still get the error. Is there anything else I am missing ?