How to download file with golang

webdav_issue

#1

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?


#2

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


#3

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)
}

#4

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

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

#5

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


#6

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