Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access-Control-Allow-Headers CORS Error #73

Open
hussainhyder23 opened this issue Nov 20, 2020 · 2 comments
Open

Access-Control-Allow-Headers CORS Error #73

hussainhyder23 opened this issue Nov 20, 2020 · 2 comments

Comments

@hussainhyder23
Copy link

I am trying to use the below code to upload my file using Uppy. However, When I am trying to do that, I'm getting CORS origin error.
Output in console : [GIN] 2020/11/21 - 00:56:46 | 204 | 337.339µs | ::1 | OPTIONS "/files/"
This is the error I am getting in my browser's console : "'http://localhost:8080/files/' from origin 'http://localhost:3000' has been blocked by CORS policy: Request header field tus-resumable is not allowed by Access-Control-Allow-Headers in preflight response."
I used router.Use(cors.Default()) as well

router.POST("/files", func(c *gin.Context) {

		s3Locker := s3store.New("edisontestbucket1", s3.New(session.Must(session.NewSession()), s3Config))
		composer := tusd.NewStoreComposer()
		s3Locker.UseIn(composer)

		handler, err := tusd.NewHandler(tusd.Config{
			BasePath:              "/files/",
			StoreComposer:         composer,
			NotifyCompleteUploads: true,
			// NotifyTerminatedUploads: true,
			// NotifyUploadProgress:    true,
			// NotifyCreatedUploads:    true,
		})
		if err != nil {
			panic(fmt.Errorf("Unable to create handler: %s", err))
		}
		go func() {
			for {
				event := <-handler.CompleteUploads
				fmt.Printf("Upload %s finished\n", event.Upload.ID)
			}
		}()
	})
@rangerthegood
Copy link

I just ran into the same problem. The issue was the ordering of the lines in my function.

See below, The line r.Use must come before the r.GET. If it was the other way, I didn't get the Access-Control-Allow-Headers header set.

`func main() {
r := gin.Default()

r.Use(cors.Default())
r.GET("/ping", func(c *gin.Context) {
	c.JSON(200, gin.H{
		"message": "pong",
	})
})

r.Run(":3000") // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")

}`

@JiahuiChen99
Copy link

@rangerthegood This solved the CORS error, what a dumb mistake it was. Thank you! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants