© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•3y ago•
2 replies
Ares

image upload content type

I'm trying to to set content type by a switch and it is taking ages to compelete. it is a switch within a for loop. so you can image the time it is taking.

is there a way to imporve this approach beside a if ... else if ... statements?

let contentType = '';
                    switch (file.file.type) {
                        case 'image/png':
                            contentType = 'image/png';
                            break;
                        case 'image/jpeg':
                            contentType = 'image/jpeg';
                            break;
                        case 'image/jpg':
                            contentType = 'image/jpg';
                            break;
                        case 'image/webp':
                            contentType = 'image/webp';
                            break;
                        default:
                            console.error('Unsupported file type');
                            continue; // Skip unsupported file types
                    }

                    const { data: storagesData, error: storageError } = await supabase.storage
                        .from('images')
                        .upload(imgUrl, arrayBuffer, {
                            upsert: false,
                            cacheControl: null,
                            contentType: contentType
                        });
let contentType = '';
                    switch (file.file.type) {
                        case 'image/png':
                            contentType = 'image/png';
                            break;
                        case 'image/jpeg':
                            contentType = 'image/jpeg';
                            break;
                        case 'image/jpg':
                            contentType = 'image/jpg';
                            break;
                        case 'image/webp':
                            contentType = 'image/webp';
                            break;
                        default:
                            console.error('Unsupported file type');
                            continue; // Skip unsupported file types
                    }

                    const { data: storagesData, error: storageError } = await supabase.storage
                        .from('images')
                        .upload(imgUrl, arrayBuffer, {
                            upsert: false,
                            cacheControl: null,
                            contentType: contentType
                        });
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

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Getting "No Content Provided" when trying to upload an image to storage
SupabaseSSupabase / help-and-questions
13mo ago
Upload image faild on storage
SupabaseSSupabase / help-and-questions
8mo ago
SvelteKit + Supabase avatar image upload
SupabaseSSupabase / help-and-questions
4y ago
Image upload taking too long
SupabaseSSupabase / help-and-questions
4y ago