Flutter - upload file to storage - StorageError (new row violates row-level security policy...)

Hello, I have created a bucket, called "avatars" and made it "public".
I am trying to upload a picture into that bucket, in Flutter.
The answer is the following
StorageError(message: new row violates row-level security policy for table "objects", statusCode: 42501, error: )

--
The code to upload is the following:
    await Supabase.initialize(
      url: "https://${Environment.supabaseUrl}.supabase.co",
      anonKey: Environment.supabaseAnon,
      debug: !kReleaseMode,
    );    
...
    File? fileToUpload;

    try {
      ///
      /// We first need to transfer the base64 content to a real file
      ///
      fileToUpload = await FileHelper().writeStringToFile('temp', 'profile_picture.png', base64Content.replaceAll('base64:', ''));

      ///
      /// Now, we need to upload the file onto the Storage bucket
      ///
      final StorageResponse<String> storageResponse = await Supabase.instance.client.storage.from('avatars').upload(
            'avatar1.jpg',
            fileToUpload,
            fileOptions: const FileOptions(cacheControl: '3600', upsert: true),
          );

      if (storageResponse.hasError) {
        log('STORAGE ERROR => ${storageResponse.error}');
      } else {
        log('STORAGE SUCCESS => ${storageResponse.data}');
      }
    } catch (e) {
      // Nothing
      log('STORAGE ERROR (Exception)=> $e');
    } finally {
      if (fileToUpload != null) {
        fileToUpload.delete();
      }
    }

I also tried to set the default "Policies" (Allow access to JPG images..) but still the same error.

Could anyone please help me?
Many thanks
Was this page helpful?