Skip to content

Commit

Permalink
update R2 examples
Browse files Browse the repository at this point in the history
  • Loading branch information
syumai committed Jan 12, 2025
1 parent c30f8b6 commit f11ec65
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions _examples/r2-image-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"

"github.com/syumai/workers"
"github.com/syumai/workers/cloudflare"
"github.com/syumai/workers/cloudflare/r2"
)

// bucketName is R2 bucket name defined in wrangler.toml.
Expand All @@ -23,8 +23,8 @@ func handleErr(w http.ResponseWriter, msg string, err error) {

type server struct{}

func (s *server) bucket() (*cloudflare.R2Bucket, error) {
return cloudflare.NewR2Bucket(bucketName)
func (s *server) bucket() (*r2.Bucket, error) {
return r2.NewBucket(bucketName)
}

func (s *server) post(w http.ResponseWriter, req *http.Request, key string) {
Expand All @@ -45,8 +45,8 @@ func (s *server) post(w http.ResponseWriter, req *http.Request, key string) {
return
}
}
_, err = bucket.Put(key, req.Body, &cloudflare.R2PutOptions{
HTTPMetadata: cloudflare.R2HTTPMetadata{
_, err = bucket.Put(key, req.Body, &r2.PutOptions{
HTTPMetadata: r2.HTTPMetadata{
ContentType: req.Header.Get("Content-Type"),
},
CustomMetadata: map[string]string{"custom-key": "custom-value"},
Expand Down
4 changes: 2 additions & 2 deletions _examples/r2-image-viewer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"

"github.com/syumai/workers"
"github.com/syumai/workers/cloudflare"
"github.com/syumai/workers/cloudflare/r2"
)

// bucketName is R2 bucket name defined in wrangler.toml.
Expand All @@ -23,7 +23,7 @@ func handleErr(w http.ResponseWriter, msg string, err error) {
// This example is based on implementation in syumai/workers-playground
// - https://github.com/syumai/workers-playground/blob/e32881648ccc055e3690a0d9c750a834261c333e/r2-image-viewer/src/index.ts#L30
func handler(w http.ResponseWriter, req *http.Request) {
bucket, err := cloudflare.NewR2Bucket(bucketName)
bucket, err := r2.NewBucket(bucketName)
if err != nil {
handleErr(w, "failed to get R2Bucket\n", err)
return
Expand Down

0 comments on commit f11ec65

Please sign in to comment.