How to download file with golang

how to download file with golang api?

first to use http.post to login the filesystem.

but the message return: {“message”:“CSRF check failed”}

how to set the cookie or the authority?

IMHO, easiest way is finding a webdav client library for golang.

use the client, but it doesnt work.
https://github.com/studio-b12/gowebdav
it return a html login page of the owncloud.

func test_download_file(webdavFilePath string, localpath string) {
	root := "myroot"
	user := "myuser"
	passwd := "***"
	client := gowebdav.NewClient(root, user, passwd)


	reader, err := client.ReadStream(webdavFilePath)
	if err != nil {
		fmt.Println("read stream err")
		return
	}

	file, _ := os.Create(localpath)
	defer file.Close()

	io.Copy(file, reader)
}

find a library in github. and it is a perfect fit.

https://github.com/remogatto/cloud.git

try to add your domain from personal panel, security section.

2 Likes

Yes. Perfect use case for CORS. Hope this helps!