Cannot add file through a Golang backend app but can add using Postman

Hi all,

I successfully setup and added file through IPFS cluster proxy using postman

But when I dit it within my Golang backend, I got the error Post "http://localhost:9095/api/v0/add": dial tcp 127.0.0.1:9095: connect: connection refused

Here is my code

func Add(c *gin.Context) {
	client, err := client.NewDefaultClient(&client.Config{Host: "localhost", Port: "9094"})

	if err != nil {
		fmt.Println("new client")
		fmt.Println(err)
		c.JSON(400, gin.H{"data": "Error"})
	} else {
		file, _, err := c.Request.FormFile("file")

		if err != nil {
			fmt.Println("multipart")
			fmt.Println(err)
			c.JSON(400, gin.H{"data": "Error"})
		} else {
			shell := client.IPFS(c)

			CID, err := shell.Add(file)

			fmt.Println("add")
			fmt.Println(err)
			c.JSON(200, gin.H{"cid": CID})
		}
	}
}

I have tried different host such as 127.0.0.1, 0.0.0.0 but none worked.

Thanks in advance.

1 Like

“Connection refused” means there is nothing listening on that port. You should double check.

Hi @hector,

But I was able to add file using Postman, so the port is supposed to be listening, right?

It is supposed to be listening yes.

How are you running things? What OS? Any firewall? Any docker, virtual machine or anything that makes localhost on one place be different from locahost on the other place?

Hi Hector,

Thanks for your clarification. My golang backend is running inside a docker, so make calls to localhost within it will not work :slight_smile:

Thanks a lot Hector.