I am getting a 204 with OPTIONS method, but the end-point doesn't seem to be hit
Just building a simple file-upload endpoint like this:
package main
import (
"cloud.google.com/go/storage"
"github.com/gin-gonic/gin"
"github.com/gin-contrib/cors"
"google.golang.org/api/option"
"io"
"log"
)
const uploadBucket = "some-cool-bucket-name"
const uploadApiKey = "some-advanced-key"
func main() {
router := gin.Default()
rg := router.Group("api/v1/photo")
{
rg.PATCH("/", uploadFile)
}
router.Use(cors.Default())
router.Run()
}
func uploadFile(c *gin.Context) {
mr, e := c.Request.MultipartReader()
if e != nil {
panic("Error reading request")
}
client, e := storage.NewClient(c, option.WithAPIKey(uploadApiKey))
bucket := client.Bucket(uploadBucket)
for {
p, e := mr.NextPart()
if e == io.EOF {
break
} else if e != nil {
panic("Error processing file")
}
w := bucket.Object(p.FileName()).NewWriter(c)
if _, e := io.Copy(w, p); e != nil {
panic("Error during chunk upload")
} else if e := w.Close(); e != nil {
panic("Could not finalize chunk writing")
}
}
}
Any ideas why?