# Unable to download files from Pydio Cells using Golang

**URL:** https://forum.pydio.com/t/unable-to-download-files-from-pydio-cells-using-golang/3105
**Category:** Pydio Cells
**Created:** [February 25, 2020, 11:10am UTC](https://forum.pydio.com/t/unable-to-download-files-from-pydio-cells-using-golang/3105 "2020-02-25T11:10:38Z")
**Posts on this page:** 19
**Page:** 1

<div class="post-metadata">

### Author: ![sid](https://avatars.discourse-cdn.com/v4/letter/s/5f9b8f/32.png) [@sid](https://forum.pydio.com/u/sid)
#### Post date: [February 25, 2020, 11:10am UTC](https://forum.pydio.com/t/unable-to-download-files-from-pydio-cells-using-golang/3105/1 "2020-02-25T11:10:38Z")

</div>

I am currently writing a Golang program for downloading files from Pydio Cells using Golang program. (Using Minio library)

The working code (for downloading all files from a given bucket in a sample server [play.min.io](http://play.min.io) is:

```auto
package main

import (
	"github.com/minio/minio-go/v6"
	"log"
  "fmt"
  "context"
  "time"
  "os"
  "io"
)

func main() {
	endpoint := "play.min.io"
	accessKeyID := "Q3AM3UQ867SPQQA43P2F"
	secretAccessKey := "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG"
	useSSL := true

	// Initialize minio client object.
	minioClient, err := minio.New(endpoint, accessKeyID, secretAccessKey, useSSL)
	if err != nil {
		log.Fatalln(err)
	}

	// Make a new bucket called mymusic.
	bucketName := "mymusic"
	location := "us-east-1"

	err = minioClient.MakeBucket(bucketName, location)
	if err != nil {
		// Check to see if we already own this bucket (which happens if you run this twice)
		exists, errBucketExists := minioClient.BucketExists(bucketName)
		if errBucketExists == nil && exists {
			log.Printf("We already own %s\n", bucketName)
		} else {
			log.Fatalln(err)
		}
	} else {
		log.Printf("Successfully created %s\n", bucketName)
	}

  // Create a done channel to control 'ListObjects' go routine.
  doneCh := make(chan struct{})

  // Indicate to our routine to exit cleanly upon return.
  defer close(doneCh)

  isRecursive := true
  objectCh := minioClient.ListObjects("mymusic", "", isRecursive, doneCh)
  for object1 := range objectCh {
    if object1.Err != nil {
      fmt.Println(object1.Err)
      return
    }
    fmt.Println(object1.Key)

    ctx, cancel := context.WithTimeout(context.Background(), 100 * time.Second)
    defer cancel()

    //object, err := minioClient.GetObjectWithContext(ctx, "mymusic", "hello.txt", minio.GetObjectOptions{})
    object, err := minioClient.GetObjectWithContext(ctx, "mymusic", object1.Key, minio.GetObjectOptions{})
    if err != nil {
      fmt.Println(err)
      return
    }

    localFile, err := os.Create("/home/Desktop/MinioDownloads/"+object1.Key)
    if err != nil {
      fmt.Println(err)
      return
    }

    if _, err = io.Copy(localFile, object); err != nil {
      fmt.Println(err)
      return
    }

  }

}

```

Now, when I modify the same for Pydio Cells, this is the .go file:

```auto
package main

import 
(
   "github.com/minio/minio-go/v6"
   "log"
  "fmt"
  "context"
  "time"
  "os"
  "io"
)

func main() {
	
	endpoint := (Some URL)
	accessKeyID := "admin"
	secretAccessKey := "admin"
	useSSL := false
	
	// Initialize minio client object.
	minioClient, err := minio.New(endpoint, accessKeyID, secretAccessKey, useSSL)
	if err != nil {
		log.Fatalln(err)
	}

  // Create a done channel to control 'ListObjects' go routine.
  doneCh := make(chan struct{})

  // Indicate to our routine to exit cleanly upon return.
  defer close(doneCh)

  isRecursive := true
  objectCh := minioClient.ListObjects("personal", "", isRecursive, doneCh)
  for object1 := range objectCh {
    if object1.Err != nil {
      fmt.Println(object1.Err)
      return
    }
    fmt.Println(object1.Key)

    ctx, cancel := context.WithTimeout(context.Background(), 100 * time.Second)
    defer cancel()

    object, err := minioClient.GetObjectWithContext(ctx, "personal", object1.Key, minio.GetObjectOptions{})
    if err != nil {
      fmt.Println(err)
      return
    }

    localFile, err := os.Create("/home/Desktop/MinioDownloads/"+object1.Key)
    if err != nil {
      fmt.Println(err)
      return
    }

    if _, err = io.Copy(localFile, object); err != nil {
      fmt.Println(err)
      return
    }

  }

}

```

On running this, I get the following error:  
XML syntax error on line 2: attribute name without = in element

I am unable to resolve this.  
Please suggest

---

<div class="post-metadata">

### Author: ![c12simple](https://yyz2.discourse-cdn.com/flex032/user_avatar/forum.pydio.com/c12simple/32/90_2.png) [@c12simple](https://forum.pydio.com/u/c12simple)
#### Post date: [February 25, 2020, 3:44pm UTC](https://forum.pydio.com/t/unable-to-download-files-from-pydio-cells-using-golang/3105/2 "2020-02-25T15:44:13Z")

</div>

Hi,  
Just for information, [https://github.com/pydio/cells-client](https://github.com/pydio/cells-client)

---

<div class="post-metadata">

### Author: ![sid](https://avatars.discourse-cdn.com/v4/letter/s/5f9b8f/32.png) [@sid](https://forum.pydio.com/u/sid)
#### Post date: [February 26, 2020, 4:33am UTC](https://forum.pydio.com/t/unable-to-download-files-from-pydio-cells-using-golang/3105/3 "2020-02-26T04:33:14Z")

</div>

Hi @c12simple,

Thanks for help. I am actually looking for those Go programming functions using which I can programatically:

1. Login to my Pydio cells server
2. Then list all the files and folders present inside it
3. Download any of those files/folders

Since I am a beginner, I don’t know much.

I have installed cec client, but in the configuration process, I am getting error (Screenshot attached):

 ![26feb01](https://canada1.discourse-cdn.com/flex032/uploads/pydio/original/2X/5/52083692e4c033bb1ec7e4799a0f591ec5f75b3d.jpeg)

My details while configuring cec:  
$ cec configure  
Server Address (provide a valid URL): (some url)  
OAuth APP ID (found in your server pydio.json): cells-client  
OAuth APP Secret (leave empty for a public client):  
✔ Yes  
Opening URL (some URL)

---

<div class="post-metadata">

### Author: ![c12simple](https://yyz2.discourse-cdn.com/flex032/user_avatar/forum.pydio.com/c12simple/32/90_2.png) [@c12simple](https://forum.pydio.com/u/c12simple)
#### Post date: [February 27, 2020, 4:37pm UTC](https://forum.pydio.com/t/unable-to-download-files-from-pydio-cells-using-golang/3105/4 "2020-02-27T16:37:25Z")

</div>

Hello,

The server is running in http or https? From error message, I guess it is in http.  
So cec has a bug with skip certificate check if you are using self-sign cert. Please wait for update version.

---

<div class="post-metadata">

### Author: ![sid](https://avatars.discourse-cdn.com/v4/letter/s/5f9b8f/32.png) [@sid](https://forum.pydio.com/u/sid)
#### Post date: [March 27, 2020, 6:04am UTC](https://forum.pydio.com/t/unable-to-download-files-from-pydio-cells-using-golang/3105/6 "2020-03-27T06:04:05Z")

</div>

Hello

I have one more doubt:

Is the Pydio Cells local storage S3 compatible?

The reason I am asking that is because Minio-go SDK functions (as mentioned in [https://docs.min.io/docs/golang-client-api-reference.html](https://docs.min.io/docs/golang-client-api-reference.html))  
, the functions like minioClient.ListBuckets(), minioClient.GetObject(), minioClient.PutObject() etc. are applicable for only S3 compatible storage

Thanks

---

<div class="post-metadata">

### Author: ![zayn](https://avatars.discourse-cdn.com/v4/letter/z/a87d85/32.png) [@zayn](https://forum.pydio.com/u/zayn)
#### Post date: [March 27, 2020, 11:26am UTC](https://forum.pydio.com/t/unable-to-download-files-from-pydio-cells-using-golang/3105/7 "2020-03-27T11:26:45Z")

</div>

Hello @sid,

I think this article will give you a better understanding of the architecture,  
[https://pydio.com/en/docs/cells/v2/understanding-datasources](https://pydio.com/en/docs/cells/v2/understanding-datasources)

> [@sid](#):
>
> The reason I am asking that is because Minio-go SDK functions (as mentioned in [MinIO Go Client API Reference — MinIO Object Storage for Linux](https://docs.min.io/docs/golang-client-api-reference.html))  
> , the functions like minioClient.ListBuckets(), minioClient.GetObject(), minioClient.PutObject() etc. are applicable for only S3 compatible storage

You should be able to interact with the local storage through the S3 api, [https://github.com/pydio/cells-client/blob/master/rest/files.go](https://github.com/pydio/cells-client/blob/master/rest/files.go), you can use the minioClient to interact with Cells.

---

<div class="post-metadata">

### Author: ![sid](https://avatars.discourse-cdn.com/v4/letter/s/5f9b8f/32.png) [@sid](https://forum.pydio.com/u/sid)
#### Post date: [March 27, 2020, 3:09pm UTC](https://forum.pydio.com/t/unable-to-download-files-from-pydio-cells-using-golang/3105/8 "2020-03-27T15:09:56Z")

</div>

Hello @zayn Thanks for help!

It would be very helpful if you could please clear this also:

In the website [Main APIs presentation | Pydio](https://pydio.com/en/docs/developer-guide/main-apis-presentation)  
it is mentioned that:

> S3 API:  
> For **manipulating the file contents** in a consistent way (uploads/downloads), Cells provides an S3-compatible API. The root of your installation can be used as an s3-compatible storage in a third party software that supports such feature. There is only one bucket available, named `io` .

> This endpoint requires the standard S3-Signature headers, which can be fairly complex to generate, so we recommend using one of the numerous libraries available out there to communicate with S3. To connect to the Cells, an S3 Client will require the following settings:

> - **Custom URL** : your Cells URL.
> - **Data Bucket** : `io`
> - **Access key and secret** : use the JWT (see Authentication section) as the API Key, and `gatewaysecret` as a fixed API Secret.

When I modified my parameters in the main() as follows:

```auto
bucket name: "io"
accessKeyID: (some api key from pydio.json file)
secretAccessKey: "gatewaysecret"

```

I now get the error `Information Error: Bucket name cannot be shorter than 3 characters`

How to resolve this?

---

<div class="post-metadata">

### Author: ![zayn](https://avatars.discourse-cdn.com/v4/letter/z/a87d85/32.png) [@zayn](https://forum.pydio.com/u/zayn)
#### Post date: [March 27, 2020, 3:59pm UTC](https://forum.pydio.com/t/unable-to-download-files-from-pydio-cells-using-golang/3105/9 "2020-03-27T15:59:58Z")

</div>

Which lib are you using, do you have an entire snippet of the code that I could test?

once you have your S3 Client you should be able to create operations, for instance here is one example that i’m currently working on

```auto
	multipartOutput, err := s3Client.CreateMultipartUpload(&s3.CreateMultipartUploadInput{
		Bucket: aws.String(bucket),
		Key: aws.String(path),
		ContentType: aws.String("application/octet-stream"),
	})

```

`bucket := "io"`  
and path is `personalf-files/file.txt`

---

<div class="post-metadata">

### Author: ![sid](https://avatars.discourse-cdn.com/v4/letter/s/5f9b8f/32.png) [@sid](https://forum.pydio.com/u/sid)
#### Post date: [March 27, 2020, 9:54pm UTC](https://forum.pydio.com/t/unable-to-download-files-from-pydio-cells-using-golang/3105/10 "2020-03-27T21:54:33Z")

</div>

Hi @zayn

I am now using Amazon’s `AWS-SDK-Go` for listing the buckets in the Pydio cells deployed by me.

My Pydio Cells was deployed as `http`

The code is:

```auto
package main

import (
	"fmt"
    "github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/aws/session"
	"github.com/aws/aws-sdk-go/service/s3"
	"github.com/aws/aws-sdk-go/aws/credentials"
)

func main() {
	sess, err := session.NewSession(&aws.Config{
    Region: aws.String("us-east-1"),
	Endpoint: aws.String(...My Pydio Cells URL...),
    Credentials: credentials.NewStaticCredentials(...My API Key..., "gatewaysecret",""),
	})

	svc := s3.New(sess)
	buckets, err := svc.ListBuckets(&s3.ListBucketsInput{})
	if err != nil {
		panic(fmt.Sprintf("failed to list buckets, %v", err))
	}
	
	for _,b := range buckets.Buckets {
		bucket := aws.StringValue(b.Name)
		fmt.Println(bucket)
	}
}

```

The above code works fine for AWS S3 storage:

Now, coming to my Pydio Cells instance, i.e., when I run this code with my Pydio Cells URL:

1. Without using `http` at the beginning, I get the error:

```auto
panic: failed to list buckets, RequestError: send request failed
caused by: Get "https://(...My Pydio Cells URL...)/": http: server gave HTTP response to HTTPS client

goroutine 1 [running]:
main.main()
        listbuckets.go:29 +0x330
exit status 2
```

1. With using `http` at the beginning, I get the error:

```auto
panic: failed to list buckets, SerializationError: failed to decode REST XML response
        status code: 200, request id:
caused by: XML syntax error on line 2: attribute name without = in element

goroutine 1 [running]:
main.main()
        listbuckets.go:29 +0x330
exit status 2
```

---

<div class="post-metadata">

### Author: ![sid](https://avatars.discourse-cdn.com/v4/letter/s/5f9b8f/32.png) [@sid](https://forum.pydio.com/u/sid)
#### Post date: [March 30, 2020, 8:39am UTC](https://forum.pydio.com/t/unable-to-download-files-from-pydio-cells-using-golang/3105/11 "2020-03-30T08:39:11Z")

</div>

@zayn @c12simple

Also, is there any Pydio API for downloading files which doesn’t internally use 3rd party libraries like AWS-SDK-Go & Minio-Go?

---

<div class="post-metadata">

### Author: ![c12simple](https://yyz2.discourse-cdn.com/flex032/user_avatar/forum.pydio.com/c12simple/32/90_2.png) [@c12simple](https://forum.pydio.com/u/c12simple)
#### Post date: [March 30, 2020, 1:07pm UTC](https://forum.pydio.com/t/unable-to-download-files-from-pydio-cells-using-golang/3105/12 "2020-03-30T13:07:28Z")

</div>

> <https://stackoverflow.com/questions/54700473/how-do-you-upload-files-folders-to-pydio-cells-using-the-pydio-cells-api/55814790#55814790>

I’m not sure that it works or not 🙂

---

<div class="post-metadata">

### Author: ![sid](https://avatars.discourse-cdn.com/v4/letter/s/5f9b8f/32.png) [@sid](https://forum.pydio.com/u/sid)
#### Post date: [March 30, 2020, 2:04pm UTC](https://forum.pydio.com/t/unable-to-download-files-from-pydio-cells-using-golang/3105/13 "2020-03-30T14:04:44Z")

</div>

1. My code for listing buckets of [demo.pydio.com](http://demo.pydio.com) using Minio-SDK library is:

```auto
package main

import (
	"log"
	"github.com/minio/minio-go"
)

func main() {
	s3Client, err := minio.New("demo.pydio.com/io", "gateway", "gatewaysecret", true)

	if err != nil {
		log.Fatalln(err)
	}

	buckets, err := s3Client.ListBuckets()
	if err != nil {
		log.Fatalln(err)
	}
	for _, bucket := range buckets {
		log.Println(bucket)
	}
```

The error I got is:

```auto
Endpoint: demo.pydio.com/io does not follow ip address or domain name standards.
exit status 1
```

1. My other code for listing buckets of [demo.pydio.com](http://demo.pydio.com) using Amazon-AWS-SDK library is:

```auto
package main

import (
	"fmt"
    "github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/aws/session"
	"github.com/aws/aws-sdk-go/service/s3"
	"github.com/aws/aws-sdk-go/aws/credentials"
)

func main() {
	sess, err := session.NewSession(&aws.Config{
    Region: aws.String("us-east-1"),
	Endpoint: aws.String("https://demo.pydio.com/io"),
	Credentials: credentials.NewStaticCredentials("gateway", "gatewaysecret",""),
	})
	
	svc := s3.New(sess)
	buckets, err := svc.ListBuckets(&s3.ListBucketsInput{})
	if err != nil {
		panic(fmt.Sprintf("failed to list buckets, %v", err))
	}
	
	for _,b := range buckets.Buckets {
		bucket := aws.StringValue(b.Name)
		fmt.Println(bucket)
	}
}
```

The output is blank on executing this 2nd code

---

<div class="post-metadata">

### Author: ![zayn](https://avatars.discourse-cdn.com/v4/letter/z/a87d85/32.png) [@zayn](https://forum.pydio.com/u/zayn)
#### Post date: [March 30, 2020, 2:13pm UTC](https://forum.pydio.com/t/unable-to-download-files-from-pydio-cells-using-golang/3105/14 "2020-03-30T14:13:43Z")

</div>

Hello @sid,

Actually you cannot really list the buckets, you can list the workspaces and then work from that.

For your first case of downloading a node take a look at this code [https://github.com/pydio/cells-client/blob/69a9b8b2c50427b92e980d5b80cab449e892014d/rest/files.go#L24](https://github.com/pydio/cells-client/blob/69a9b8b2c50427b92e980d5b80cab449e892014d/rest/files.go#L24)

pathToFile is something like `workspace/path-to-node` and bucketname is always the same `io`(for local storage datasources).

Therefore you must either list the workspaces (look at the code below in this [https://github.com/pydio/cells-client/blob/master/rest/files.go](https://github.com/pydio/cells-client/blob/master/rest/files.go)) we make use of our SDK and the S3 SDK for the s3 operations.

edit: if you want I can write you a little code snippet to show you how to downlaod a node from the demo

---

<div class="post-metadata">

### Author: ![sid](https://avatars.discourse-cdn.com/v4/letter/s/5f9b8f/32.png) [@sid](https://forum.pydio.com/u/sid)
#### Post date: [March 30, 2020, 2:22pm UTC](https://forum.pydio.com/t/unable-to-download-files-from-pydio-cells-using-golang/3105/15 "2020-03-30T14:22:09Z")

</div>

Thanks @zayn

It would be really helpful if you could share snippet of code to download a node from the demo pydio

---

<div class="post-metadata">

### Author: ![sid](https://avatars.discourse-cdn.com/v4/letter/s/5f9b8f/32.png) [@sid](https://forum.pydio.com/u/sid)
#### Post date: [April 2, 2020, 5:02am UTC](https://forum.pydio.com/t/unable-to-download-files-from-pydio-cells-using-golang/3105/16 "2020-04-02T05:02:01Z")

</div>

@zayn

Kindly share some small simple working code to download a node from the demo pydio using golang

---

<div class="post-metadata">

### Author: ![bsinou](https://yyz2.discourse-cdn.com/flex032/user_avatar/forum.pydio.com/bsinou/32/476_2.png) [@bsinou](https://forum.pydio.com/u/bsinou)
#### Post date: [April 2, 2020, 7:14am UTC](https://forum.pydio.com/t/unable-to-download-files-from-pydio-cells-using-golang/3105/17 "2020-04-02T07:14:01Z")

</div>

Hey Guys,

Just for the record, it would be much better if you choose another target to test your APIs and PoC.  
I know some of the sample code in the doc are giving the demo as an example, but that was a bad idea and will be changed promptly.

I thank you for your understanding.

Bruno

---

<div class="post-metadata">

### Author: ![sid](https://avatars.discourse-cdn.com/v4/letter/s/5f9b8f/32.png) [@sid](https://forum.pydio.com/u/sid)
#### Post date: [April 2, 2020, 7:32am UTC](https://forum.pydio.com/t/unable-to-download-files-from-pydio-cells-using-golang/3105/18 "2020-04-02T07:32:34Z")

</div>

@bsinou

Kindlly send that doc link please

Thanks

---

<div class="post-metadata">

### Author: ![GwynethLlewelyn](https://yyz2.discourse-cdn.com/flex032/user_avatar/forum.pydio.com/gwynethllewelyn/32/2419_2.png) [@GwynethLlewelyn](https://forum.pydio.com/u/GwynethLlewelyn)
#### Post date: [March 27, 2021, 8:39pm UTC](https://forum.pydio.com/t/unable-to-download-files-from-pydio-cells-using-golang/3105/20 "2021-03-27T20:39:17Z")

</div>

I apologise to bump a thread that did not get a reply for a year. I can only assume that either:

1. The OP has found a solution for his troubles in the past year, but he forgot to explain how he fixed it (that would be the more obvious reason);
2. The many offers of help, links, documentation, etc. were sent privately, perhaps because they had sensitive data, and therefore cannot be published publicly here;
3. The OP gave completely up on Pydio Cells and is using a different solution ☹

If I’m wrong on all the above, please accept my apologies. I, too, have been trying to figure out how to do all (or any!) of the above…

---

<div class="post-metadata">

### Author: ![GwynethLlewelyn](https://yyz2.discourse-cdn.com/flex032/user_avatar/forum.pydio.com/gwynethllewelyn/32/2419_2.png) [@GwynethLlewelyn](https://forum.pydio.com/u/GwynethLlewelyn)
#### Post date: [August 14, 2021, 7:44pm UTC](https://forum.pydio.com/t/unable-to-download-files-from-pydio-cells-using-golang/3105/21 "2021-08-14T19:44:07Z")

</div>

> [@sid](#):
>
> I now get the error `Information Error: Bucket name cannot be shorter than 3 characters`

Well, at least I can answer this one: @charles has created a _second_ bucket, pointing to the same place, with the name [`data`](https://forum.pydio.com/t/synology-cloud-sync/397/6). Although the ‘official’ bucket is still named `io`, it can be replaced by `data` in most situations where software enforces the 3-character-minimum limit…

(aye, I’m _still_ looking for solutions to get flawless S3 sync to Pydio Cells myself…)
