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 is:
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:
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