[GH-ISSUE #196] Error - Download file #2180

Closed
opened 2026-03-15 17:55:26 +03:00 by kerem · 2 comments
Owner

Originally created by @WillRy on GitHub (Mar 19, 2020).
Original GitHub issue: https://github.com/fsouza/fake-gcs-server/issues/196

Hello everyone,

Sorry to bother opening an issue, but I have a question about the implementation, because I'm having an error when trying to download a file.

When downloading the file with the code:


func (video *Video) Download(bucketName string, storagePath string) (Video, error) {
	ctx := context.TODO()

	//client, err := storage.NewClient(ctx)
	transCfg := &http.Transport{
		TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, // ignore expired SSL certificates
	}
	httpClient := &http.Client{Transport: transCfg}

	client, err := storage.NewClient(ctx, option.WithEndpoint("https://fake:4443/storage/v1/"), option.WithHTTPClient(httpClient))


	if err != nil {
		video.Status = "error"
		fmt.Println(err.Error())
		return *video, err
	}


	bkt := client.Bucket(bucketName)

	obj := bkt.Object(video.Path)

	r, err := obj.NewReader(ctx)

	if err != nil {
		video.Status = "error"
		fmt.Println(err.Error())
		return *video, err
	}

	defer r.Close()

	body, err := ioutil.ReadAll(r)
	if err != nil {
		video.Status = "error"
		fmt.Println(err.Error())
		return *video, err
	}

	f, err := os.Create(storagePath+"/"+video.Uuid+".mp4");

	if err != nil {
		video.Status = "error"
		fmt.Println(err.Error())
		return *video, err
	}

	_, err = f.Write(body)

	if err != nil {
		video.Status = "error"
		fmt.Println(err.Error())
		return *video, err
	}

	defer f.Close()

	fmt.Println("Video ", video.Uuid, "has been stored")

	return *video, nil
}

The error comes from: newReader

Error:
storage: object doesn't exist

If I access the file via URL, I can do it normally.

The repository for my application is this:
https://github.com/WillRy/golang-gcs-test

obs. I have files pre-loaded through volumes, in docker-compose.yaml

Did I make a mistake?

Thank you very much in advance.

Originally created by @WillRy on GitHub (Mar 19, 2020). Original GitHub issue: https://github.com/fsouza/fake-gcs-server/issues/196 Hello everyone, Sorry to bother opening an issue, but I have a question about the implementation, because I'm having an error when trying to download a file. When downloading the file with the code: ```golang func (video *Video) Download(bucketName string, storagePath string) (Video, error) { ctx := context.TODO() //client, err := storage.NewClient(ctx) transCfg := &http.Transport{ TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, // ignore expired SSL certificates } httpClient := &http.Client{Transport: transCfg} client, err := storage.NewClient(ctx, option.WithEndpoint("https://fake:4443/storage/v1/"), option.WithHTTPClient(httpClient)) if err != nil { video.Status = "error" fmt.Println(err.Error()) return *video, err } bkt := client.Bucket(bucketName) obj := bkt.Object(video.Path) r, err := obj.NewReader(ctx) if err != nil { video.Status = "error" fmt.Println(err.Error()) return *video, err } defer r.Close() body, err := ioutil.ReadAll(r) if err != nil { video.Status = "error" fmt.Println(err.Error()) return *video, err } f, err := os.Create(storagePath+"/"+video.Uuid+".mp4"); if err != nil { video.Status = "error" fmt.Println(err.Error()) return *video, err } _, err = f.Write(body) if err != nil { video.Status = "error" fmt.Println(err.Error()) return *video, err } defer f.Close() fmt.Println("Video ", video.Uuid, "has been stored") return *video, nil } ``` The error comes from: **newReader** **Error:** storage: object doesn't exist If I access the file via URL, I can do it normally. The repository for my application is this: https://github.com/WillRy/golang-gcs-test obs. I have files pre-loaded through volumes, in docker-compose.yaml Did I make a mistake? Thank you very much in advance.
kerem closed this issue 2026-03-15 17:55:31 +03:00
Author
Owner

@fsouza commented on GitHub (Mar 20, 2020):

Hey there, thanks for opening the issue and providing a reproducer! You need to set the public-host and use that in your client.

I've updated the Go example to show how to do that: github.com/fsouza/fake-gcs-server@4ad5c60b79.

<!-- gh-comment-id:601757600 --> @fsouza commented on GitHub (Mar 20, 2020): Hey there, thanks for opening the issue and providing a reproducer! You need to set the public-host and use that in your client. I've updated the Go example to show how to do that: https://github.com/fsouza/fake-gcs-server/commit/4ad5c60b79c955cebf0017a546e61672c23a7a26.
Author
Owner

@WillRy commented on GitHub (Mar 21, 2020):

This tool is extremely useful, thanks for the help

<!-- gh-comment-id:601969707 --> @WillRy commented on GitHub (Mar 21, 2020): This tool is extremely useful, thanks for the help
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/fake-gcs-server#2180
No description provided.