Git Product home page Git Product logo

storage-go's Introduction

Storage GO

This library is a Golang client for the Supabase Storage API. It's a collection of helper functions that help you manage your buckets through the API.

Quick start guide

Install

go get github.com/supabase-community/storage-go

Connecting to the storage backend

package main

import (
	"fmt"
	"log"
	"os"

	storage_go "github.com/supabase-community/storage-go"
)

func main() {
	storageClient := storage_go.NewClient("https://<project-reference-id>.supabase.co/storage/v1", "<project-secret-api-key>", nil)
}

Handling resources

Handling Storage Buckets

  • Create a new Storage bucket:
  result, err := storageClient.CreateBucket("bucket-id", storage_go.BucketOptions{
    Public: true,
  })
  • Retrieve the details of an existing Storage bucket:
  result, err := storageClient.GetBucket("bucket-id")
  • Update a new Storage bucket:
  result, err := storageClient.UpdateBucket("bucket-id", storage_go.BucketOptions{
    Public: true,
  })
  • Remove all objects inside a single bucket:
  result, err := storageClient.EmptyBucket("bucket-id")
  • Delete an existing bucket (a bucket can't be deleted with existing objects inside it):
  result, err := storageClient.DeleteBucket("bucket-id")
  • Retrieve the details of all Storage buckets within an existing project:
  result, err := storageClient.ListBuckets("bucket-id")

Handling Files

  fileBody := ... // load your file here

  result, err := storageClient.UploadFile("test", "test.txt", fileBody)

Note: The upload method also accepts a map of optional parameters.

  • Download a file from an exisiting bucket:
  result, err := storageClient.DownloadFile("bucket-id", "test.txt")
  • List all the files within a bucket:
  result, err := storageClient.ListFiles("bucket-id", "", storage_go.FileSearchOptions{
      Limit:  10,
      Offset: 0,
      SortByOptions: storage_go.SortBy{
      Column: "",
      Order:  "",
    },
  })

Note: The list method also accepts a map of optional parameters.

  • Replace an existing file at the specified path with a new one:
  fileBody := ... // load your file here

  result, err := storageClient.UpdateFile("test", "test.txt", file)
  • Move an existing file:
  result, err := storageClient.MoveFile("test", "test.txt", "random/test.txt")
  • Delete files within the same bucket:
  result, err := storageClient.RemoveFile("test", []string{"book.pdf"})
  • Create signed URL to download file without requiring permissions:
  const expireIn = 60

  result, err := storageClient.CreateSignedUrl("test", "test.mp4", expireIn)
  • Retrieve URLs for assets in public buckets:
  result, err := storageClient.GetPublicUrl("test", "book.pdf")
  • Create an signed URL and upload to signed URL:
  fileBody := ... // load your file here

  resp, err := storageClient.CreateSignedUploadUrl("test", "test.txt")
  res, err := storageClient.UploadToSignedUrl(resp.Url, file)

License

storage-go's People

Contributors

tranhoangvuit avatar nikhilcodes avatar jerichosiahaya avatar morgenstern2573 avatar 01zulfi avatar dilutedev avatar muratmirgun avatar bjuan210302 avatar i-pip avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.