swift icon indicating copy to clipboard operation
swift copied to clipboard

upload/download large files

Open lll-phill-lll opened this issue 7 years ago • 4 comments

Hello, I try to understand how to use the library, but I can't even after reading testing files. Can you provide an example of code for uploading and downloading large file (> 5gb)?

func Upload() {
	conn := swift.Connection{
		UserName: "<username>",
		ApiKey:   "<key>",
		AuthUrl:  "https://identity.api.rackspacecloud.com/v1.0/",
		Region:   "<region>",
	}
	err := conn.Authenticate()
	if err != nil {
		fmt.Println(err)
	}
	opts := swift.LargeObjectOpts{
		Container:  "<container_name>",
		ObjectName: "fileName.txt",
		ChunkSize:  5,
		CheckHash:  true,
	}

	file, err := conn.StaticLargeObjectCreate(&opts)
	if err != nil {
		fmt.Println(err)
	}

	localFile, err := os.Open("FileToUpload.txt")
	if err != nil {
		fmt.Println(err)
	}
	defer localFile.Close()

	_, err = io.Copy(file, localFile)
	if err != nil {
		fmt.Println(err) // Generates error "Object not found"
	}
	err = file.Close()
	if err != nil {
		fmt.Println("cant close", err) // Generates error "Object not found"
	}
}

I'm using this code, but it fails with error "Object not found". Hope for your help. Thank you!

lll-phill-lll avatar Aug 29 '18 15:08 lll-phill-lll

I can't see anything obviously wrong with your code.

I suspect this is to do with swift eventual consistency...

You are using a very small ChunkSize which means swift will create lots of objects very quickly and have trouble listing them back.

Try using a larger ChunkSize (say 100MB) and uploading a bigger file?

Which provider are you using?

ncw avatar Sep 04 '18 13:09 ncw

Me too.I use the swift API provided by CEPH radosgw.

taotiepp avatar Sep 19 '18 10:09 taotiepp

download large files oom

zhaokai5520 avatar Sep 09 '20 13:09 zhaokai5520

The 404 may be because the segments container is missing. It will automatically look for a [containerNamer]_segments container to put the segments in and will fail with a 404 if it's not there.

spatialbits avatar Sep 18 '23 23:09 spatialbits