Using the MinIO API via curl
Using the MinIO API via curl
is straightforward, as MinIO is compatible with Amazon S3 API, so most commands follow a similar syntax. Here’s a guide on how to use curl
with the MinIO API for some common operations like uploading, downloading, and managing objects.
Prerequisites
- Access Key and Secret Key: Obtain your MinIO Access Key and Secret Key.
- MinIO Endpoint: Know your MinIO server endpoint, e.g.,
http://localhost:9000
. - Bucket: You may need an existing bucket name, or create a new one using the commands below.
Authentication Header
For requests to work with MinIO, you need to include authentication in the headers. MinIO uses AWS Signature Version 4 for signing requests.
Common Examples
1. List Buckets
To list all buckets in your MinIO account, use:
curl -X GET \
--url "http://localhost:9000/" \
-H "Authorization: AWS <AccessKey>:<Signature>"
2. Create a Bucket
To create a new bucket, use:
curl -X PUT \
--url "http://localhost:9000/<bucket-name>" \
-H "Authorization: AWS <AccessKey>:<Signature>"
Replace <bucket-name>
with your desired bucket name.
3. Upload an Object
To upload a file to a bucket, you can use the PUT
method.
curl -X PUT \
--url "http://localhost:9000/<bucket-name>/<object-name>" \
-H "Authorization: AWS <AccessKey>:<Signature>" \
--upload-file "<file-path>"
Replace <bucket-name>
with the name of your bucket, <object-name>
with the name you want for the uploaded object, and <file-path>
with the path to the file on your system.
4. Download an Object
To download an object, use the GET
method.
curl -X GET \
--url "http://localhost:9000/<bucket-name>/<object-name>" \
-H "Authorization: AWS <AccessKey>:<Signature>" \
-o "<local-file-path>"
Replace <bucket-name>
, <object-name>
, and <local-file-path>
accordingly.
5. List Objects in a Bucket
To list all objects in a bucket, use:
curl -X GET \
--url "http://localhost:9000/<bucket-name>" \
-H "Authorization: AWS <AccessKey>:<Signature>"
Generating the Signature
The Authorization
header should contain a signature created using AWS Signature Version 4, which can be complex to generate manually. It may be easier to use tools, libraries, or pre-built clients like the MinIO Client (mc
) or AWS SDKs to handle this signature.
Automating the Signing Process
Alternatively, tools like AWS CLI, MinIO Client (mc
), or libraries for Python, Java, etc., can make requests easier and handle the signing process internally.
Let me know if you need additional examples or help with signing.
댓글
댓글 쓰기