0Pricing
Supabase Backend as a Service · 강의

Supabase 버킷에 파일 저장

저장소 버킷을 만들고 관리하며 다양한 파일 유형을 프로그래밍 방식으로 Supabase 프로젝트에 업로드하는 방법을 이해합니다.

Supabase 버킷에 파일 저장은(는) CoddyKit의 무료 Supabase Backend as a Service 강의입니다. 이것은 4개 중 1번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Supabase Backend as a Service 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Supabase Backend as a Service 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

Welcome to Supabase Storage

Managing files like images, videos, and documents is crucial for many apps. Supabase offers a robust, S3-compatible object storage solution right out of the box!

It's designed for scalability and security, letting you store and serve user-generated content or application assets with ease.

Understanding Storage Buckets

Think of a bucket as a top-level folder or container for your files. Each Supabase project can have multiple buckets.

  • Organize files by type (e.g., avatars, product-images).
  • Set different security rules for each bucket.
  • Buckets are isolated, meaning files in one bucket don't mix with another.

Create a Bucket in the Dashboard

You can create buckets directly from the Supabase Dashboard. Navigate to the Storage section and click "New bucket".

Give it a unique name and decide if it should be public or private. We'll explore these options next!

Public or Private Access?

This is a key decision when creating a bucket:

  • Public Buckets: Anyone with the URL can access files. Great for static assets like profile pictures or public documents.
  • Private Buckets: Files require authentication and specific policies to be accessed. Ideal for sensitive user data or premium content.

You can change this setting later, but it's good to plan ahead!

Setting Up for Uploads (JS)

To upload files from your app, you'll use the Supabase client library. First, ensure you have your Supabase URL and anon key initialized.

We'll use a simple JavaScript example. Imagine supabase is your initialized client.

import { createClient } from '@supabase/supabase-js';

const SUPABASE_URL = 'YOUR_SUPABASE_URL';
const SUPABASE_ANON_KEY = 'YOUR_ANON_KEY';

const supabase = createClient(SUPABASE_URL, SUPABASE_ANON_KEY);

console.log('Supabase client initialized.');

Programmatically Upload a File

The storage.from().upload() method is your go-to for uploading. It needs the bucket name, the path within the bucket, and the file itself.

Let's simulate uploading a simple text file. In a real app, you'd get the file from an HTML <input type="file">.

import { createClient } from '@supabase/supabase-js';

const SUPABASE_URL = 'YOUR_SUPABASE_URL';
const SUPABASE_ANON_KEY = 'YOUR_ANON_KEY';

const supabase = createClient(SUPABASE_URL, SUPABASE_ANON_KEY);

async function uploadFile() {
  // In a real app, 'file' would come from an input element
  const mockFile = new File(['Hello CoddyKit!'], 'hello.txt', {
    type: 'text/plain',
  });

  const { data, error } = await supabase.storage
    .from('my-first-bucket') // Replace with your bucket name
    .upload('public/hello_world.txt', mockFile);

  if (error) {
    console.error('Upload error:', error.message);
  } else {
    console.log('Upload successful:', data);
  }
}

uploadFile();

File Paths & Overwrite Behavior

The 'path' in .upload('path/to/file.txt', file) determines where your file lands within the bucket.

  • 'my-image.jpg': Uploads to the bucket's root.
  • 'avatars/user123.png': Creates an avatars folder if it doesn't exist.

By default, uploading to an existing path will overwrite the old file. You can control this with the upsert option.

Controlling Overwrites with Upsert

The upsert option in the upload method lets you decide what happens if a file with the same path already exists.

  • upsert: true (default): Overwrites the existing file.
  • upsert: false: Returns an error if a file with the same path exists, preventing accidental overwrites.

Use upsert: false when you want to ensure unique file names.

import { createClient } from '@supabase/supabase-js';

const SUPABASE_URL = 'YOUR_SUPABASE_URL';
const SUPABASE_ANON_KEY = 'YOUR_ANON_KEY';

const supabase = createClient(SUPABASE_URL, SUPABASE_ANON_KEY);

async function uploadUniqueFile() {
  const mockFile = new File(['Unique content!'], 'unique.txt', {
    type: 'text/plain',
  });

  // This will fail if 'public/unique.txt' already exists
  const { data, error } = await supabase.storage
    .from('my-first-bucket') // Replace with your bucket name
    .upload('public/unique.txt', mockFile, { upsert: false });

  if (error) {
    console.error('Upload failed (file exists or other error):', error.message);
  } else {
    console.log('Unique upload successful:', data);
  }
}

uploadUniqueFile();

Handles All Your File Needs

Supabase Storage isn't limited to just images or text files. It can handle any file type you throw at it!

  • Images: PNG, JPG, GIF, SVG
  • Videos: MP4, MOV, WebM
  • Documents: PDF, DOCX, XLSX
  • Audio: MP3, WAV

Just ensure your client-side code provides the correct file object.

Quick Check on Buckets

You've learned about Supabase Storage buckets and how to upload files. Let's test your understanding!

Recap: Storing Files

Great job! You've learned the fundamentals of Supabase Storage:

  • What buckets are and how to create them.
  • The difference between public and private buckets.
  • How to programmatically upload files using the Supabase client.
  • Controlling file overwrites with the upsert option.

Next, you'll dive into securing your files with Storage Policies!

자주 묻는 질문

“Supabase 버킷에 파일 저장” 강의는 무료인가요?

네 — “Supabase 버킷에 파일 저장” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Supabase Backend as a Service 강의 전체를 잠금 해제할 수 있습니다. Supabase Backend as a Service 강의에는 총 4개의 강의가 포함되어 있습니다.

“Supabase 버킷에 파일 저장”에서 뭘 배우나요?

저장소 버킷을 만들고 관리하며 다양한 파일 유형을 프로그래밍 방식으로 Supabase 프로젝트에 업로드하는 방법을 이해합니다. 브라우저에서 직접 실행하는 실습 코드로 Supabase Backend as a Service을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Supabase Backend as a Service을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 Supabase Backend as a Service은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 1번째 강의입니다.

“Supabase 버킷에 파일 저장” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 Supabase Backend as a Service 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 Supabase Backend as a Service 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. Supabase 버킷에 파일 저장
  2. 정책으로 접근 권한 관리
  3. 미디어 업로드와 가져오기
  4. 이미지 변환과 서명된 URL
← Supabase Backend as a Service(으)로 돌아가기