Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How does go client sdk create dir path in a bucket ? #3555

Closed
goodforever opened this issue Jan 10, 2017 · 8 comments
Closed

How does go client sdk create dir path in a bucket ? #3555

goodforever opened this issue Jan 10, 2017 · 8 comments

Comments

@goodforever
Copy link

How does go client sdk create dir path in a bucket ?

@harshavardhana
Copy link
Member

@goodforever we don't support directories on Minio. You can just upload and object with prefix parent dirs are automatically created.

@ghost
Copy link

ghost commented Jan 11, 2017

@harshavardhana i not quite understand what you said You can just upload and object with prefix parent dirs are automatically created. when i upload the file, the minio-browser only upload the file without the parent dirs. Do you mean mc cp XXX

@harshavardhana
Copy link
Member

harshavardhana commented Jan 11, 2017

@harshavardhana i not quite understand what you said You can just upload and object with prefix parent dirs are automatically created. when i upload the file, the minio-browser only upload the file without the parent dirs. Do you mean mc cp XXX

I am talking about mc cp browser is not meant for uploading large sets of files. One if better off using tools like this.

$ mc cp /etc/issue play/harsha/1/2/3/3/3/3/3/3/3/1
/etc/issue:                26 B / 26 B ┃▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓┃ 100.00% 221 B/s 0s
$ mc ls play/harsha/1/2/
[2017-01-11 00:34:31 PST]     0B 3/
$ mc ls play/harsha/1/2/ -r
[2017-01-11 00:34:14 PST]    26B 3/3/3/3/3/3/3/1
```

@harshavardhana
Copy link
Member

Not just mc cp you can use any tools like aws cli , s3cmd etc.

@harshavardhana
Copy link
Member

harshavardhana commented Jan 11, 2017

From an SDK point of view

package main

import (
	"bytes"
	"log"

	minio "github.com/minio/minio-go"
)

func main() {
	// Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-testfile, my-bucketname and
	// my-objectname are dummy values, please replace them with original values.

	// Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access.
	// This boolean value is the last argument for New().

	// New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically
	// determined based on the Endpoint value.
	s3Client, err := minio.New("YOUR-SERVER:9000", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true)
	if err != nil {
		log.Fatalln(err)
	}

	n, err := s3Client.PutObject("my-bucketname", "2/3/my/prefix/object", bytes.NewReader([]byte("Hello, World")), "application/octet-stream")
	if err != nil {
		log.Fatalln(err)
	}
	log.Println("Uploaded", "2/3/my/prefix/object", " of size: ", n, "Successfully.")
}

2/3/my/prefix/ prefix of choice and object.

@harshavardhana
Copy link
Member

what is the name format with prefix parent dirs ? Can you give a example ?

@goodforever here is the example

package main

import (
	"bytes"
	"log"

	minio "github.com/minio/minio-go"
)

func main() {
	// Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-testfile, my-bucketname and
	// my-objectname are dummy values, please replace them with original values.

	// Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access.
	// This boolean value is the last argument for New().

	// New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically
	// determined based on the Endpoint value.
	s3Client, err := minio.New("YOUR-SERVER:9000", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true)
	if err != nil {
		log.Fatalln(err)
	}

	n, err := s3Client.PutObject("my-bucketname", "2/3/my/prefix/object", bytes.NewReader([]byte("Hello, World")), "application/octet-stream")
	if err != nil {
		log.Fatalln(err)
	}
	log.Println("Uploaded", "2/3/my/prefix/object", " of size: ", n, "Successfully.")
}

Observe here '2/3/my/prefix' is the parent directory for the object named object . On Minio this is a flat key conceptually there is no directory.

@goodforever
Copy link
Author

Thanks ,I just need this what you said.

@lock
Copy link

lock bot commented May 21, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot unassigned koolhead17 May 21, 2020
@lock lock bot locked as resolved and limited conversation to collaborators May 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants