© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•4y ago•
1 reply
boeledi

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: )
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();
      }
    }
    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
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

upload image new row violates row-level security policy error
SupabaseSSupabase / help-and-questions
3y ago
StorageApiError: new row violates row-level security policy
SupabaseSSupabase / help-and-questions
4mo ago
upsert() new row violates row-level security policy
SupabaseSSupabase / help-and-questions
4y ago
New row violates row-level security policy for table
SupabaseSSupabase / help-and-questions
4y ago