# Downloaded file from storj

**URL:** <https://forum.storj.io/t/downloaded-file-from-storj/827>\
**Category:** troubleshooting\
**Created:** [July 23, 2019, 10:25am UTC](https://forum.storj.io/t/downloaded-file-from-storj/827 "2019-07-23T10:25:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![shivam201312](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/shivam201312/32/60_2.png) [@shivam201312](https://forum.storj.io/u/shivam201312)\
**Post date:** [July 23, 2019, 10:25am UTC](https://forum.storj.io/t/downloaded-file-from-storj/827/1 "2019-07-23T10:25:25Z")

</div>

I uploaded a text file to my Storj bucket at a specific upload path.

Now, I want to download this file, which I uploaded, so I wrote the following lines:

// Open file  
obj, err := bucket.OpenObject(ctx, “test/log.txt”)  
if err != nil {  
return err  
}  
defer errCatch(obj.Close)

```
// Get a reader for the entire file
r, err := obj.DownloadRange(ctx, 0, -1)
if err != nil {
    return err
}
defer errCatch(r.Close)

```

Now, I just want that the los.txt which I uploaded earlier gets downloaded to my present working directory.

By using ioutil, I am only able to read the file and print it.

Please guide me.

---

<div class="post-metadata">

**Author:** ![BlackDuck](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/blackduck/32/38_2.png) [@BlackDuck](https://forum.storj.io/u/BlackDuck)\
**Post date:** [July 23, 2019, 10:51am UTC](https://forum.storj.io/t/downloaded-file-from-storj/827/2 "2019-07-23T10:51:27Z")

</div>

First every function is already implemented in uplink you could take examples from there. [Copy](https://github.com/storj/storj/blob/53d96be44a692a8903a832422c52ecf5e4dad9f7/cmd/uplink/cmd/cp.go)

You could extend your example with

```auto
var reader io.ReadCloser
reader = r

file, err := os.Create("filename")
if err != nil {
		fmt.Println("Error creating file")
		return
	}
defer file.Close()

_, err = io.Copy(file, reader)
	if err != nil {
		return err
	}

```

WARNING i wrote this just down from scratch, it is untested but should write your output to a file. If this already exist it will be overwritten. You need to extend this for you needs.

---

<div class="post-metadata">

**Author:** ![shivam201312](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/shivam201312/32/60_2.png) [@shivam201312](https://forum.storj.io/u/shivam201312)\
**Post date:** [July 24, 2019, 5:07am UTC](https://forum.storj.io/t/downloaded-file-from-storj/827/3 "2019-07-24T05:07:45Z")

</div>

@BlackDuck Thank you 😃😃
