Skip to content

Commit 3967037

Browse files
Merge branch 'supabase-community:dev' into dev
2 parents 5b5eeb2 + b84c70d commit 3967037

File tree

1 file changed

+112
-34
lines changed

1 file changed

+112
-34
lines changed

README.md

Lines changed: 112 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
This library is a Golang client for the [Supabase Storage API](https://supabase.com/docs/guides/storage). It's a collection of helper functions that help you manage your buckets through the API.
44

5-
## Quick start
5+
## Quick start guide
66

7-
Install
7+
#### Install
88

99
```shell
1010
go get github.com/supabase-community/storage-go
1111
```
1212

13-
Usage
13+
### Connecting to the storage backend
1414

1515
```go
1616
package main
@@ -24,49 +24,127 @@ import (
2424
)
2525

2626
func main() {
27-
client := storage_go.NewClient("https://<project-reference-id>.supabase.co/storage/v1", "<project-secret-api-key>", nil)
27+
storageClient := storage_go.NewClient("https://<project-reference-id>.supabase.co/storage/v1", "<project-secret-api-key>", nil)
28+
}
29+
```
2830

29-
// Create a new bucket
30-
bucket, err := client.CreateBucket("bucket-id", storage_go.BucketOptions{Public: true})
31+
### Handling resources
3132

32-
if err.Error != "" {
33-
log.Fatal("error creating bucket, ", err)
34-
}
33+
#### Handling Storage Buckets
3534

36-
// Upload a file
37-
file, err := os.Open("dummy.txt")
38-
if err != nil {
39-
panic(err)
40-
}
35+
- Create a new Storage bucket:
4136

42-
resp := client.UploadFile("bucket-name", "file.txt", file)
43-
fmt.Println(resp)
37+
```go
38+
result, err := storageClient.CreateBucket("bucket-id", storage_go.BucketOptions{
39+
Public: true,
40+
})
41+
```
4442

45-
// Update Bucket
46-
response, err := client.UpdateBucket(bucket.Id, storage_go.BucketOptions{Public: true})
47-
fmt.Println(response)
43+
- Retrieve the details of an existing Storage bucket:
4844

49-
// Empty Bucket
50-
response, err = client.EmptyBucket(bucket.Id)
51-
fmt.Println(response)
45+
```go
46+
result, err := storageClient.GetBucket("bucket-id")
47+
```
5248

53-
// Delete Bucket
54-
response, err = client.DeleteBucket(bucket.Id)
55-
fmt.Println(response)
49+
- Update a new Storage bucket:
5650

57-
// Get a bucket by its id
58-
bucket = GetBucket("bucket-id")
59-
fmt.Println(bucket)
51+
```go
52+
result, err := storageClient.UpdateBucket("bucket-id", storage_go.BucketOptions{
53+
Public: true,
54+
})
55+
```
6056

61-
// Get all buckets
62-
fmt.Println(client.ListBuckets())
57+
- Remove all objects inside a single bucket:
6358

64-
}
59+
```go
60+
result, err := storageClient.EmptyBucket("bucket-id")
61+
```
62+
63+
- Delete an existing bucket (a bucket can't be deleted with existing objects inside it):
64+
65+
```go
66+
result, err := storageClient.DeleteBucket("bucket-id")
67+
```
68+
69+
- Retrieve the details of all Storage buckets within an existing project:
70+
71+
```go
72+
result, err := storageClient.ListBuckets("bucket-id")
73+
```
74+
75+
#### Handling Files
76+
77+
```go
78+
fileBody := ... // load your file here
79+
80+
result, err := storageClient.UploadFile("test", "test.txt", fileBody)
6581
```
6682

67-
> Note to self:
68-
> Update after tagging:
69-
> GOPROXY=proxy.golang.org go list -m github.com/supabase-community/[email protected]
83+
> Note: The `upload` method also accepts a map of optional parameters.
84+
85+
- Download a file from an exisiting bucket:
86+
87+
```go
88+
result, err := storageClient.DownloadFile("bucket-id", "test.txt")
89+
```
90+
91+
- List all the files within a bucket:
92+
93+
```go
94+
result, err := storageClient.ListFiles("bucket-id", "", storage_go.FileSearchOptions{
95+
Limit: 10,
96+
Offset: 0,
97+
SortByOptions: storage_go.SortBy{
98+
Column: "",
99+
Order: "",
100+
},
101+
})
102+
```
103+
104+
> Note: The `list` method also accepts a map of optional parameters.
105+
106+
- Replace an existing file at the specified path with a new one:
107+
108+
```go
109+
fileBody := ... // load your file here
110+
111+
result, err := storageClient.UpdateFile("test", "test.txt", file)
112+
```
113+
114+
- Move an existing file:
115+
116+
```go
117+
result, err := storageClient.MoveFile("test", "test.txt", "random/test.txt")
118+
```
119+
120+
- Delete files within the same bucket:
121+
122+
```go
123+
result, err := storageClient.RemoveFile("test", []string{"book.pdf"})
124+
```
125+
126+
- Create signed URL to download file without requiring permissions:
127+
128+
```go
129+
const expireIn = 60
130+
131+
result, err := storageClient.CreateSignedUrl("test", "test.mp4", expireIn)
132+
```
133+
134+
- Retrieve URLs for assets in public buckets:
135+
136+
```go
137+
result, err := storageClient.GetPublicUrl("test", "book.pdf")
138+
```
139+
140+
- Create an signed URL and upload to signed URL:
141+
142+
```go
143+
fileBody := ... // load your file here
144+
145+
resp, err := storageClient.CreateSignedUploadUrl("test", "test.txt")
146+
res, err := storageClient.UploadToSignedUrl(resp.Url, file)
147+
```
70148

71149
## License
72150

0 commit comments

Comments
 (0)