How to use curl with minio - minio/wiki GitHub Wiki
Objective:
How to use curl with MinIO
Links from where we got it:
PUT:
cd /Users/cniackz/Desktop
bucket=testing
file=arbol.jpg
host=play.min.io
s3_key='Q3AM3UQ867SPQQA43P2F'
s3_secret='zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG'
resource="/testing/arbol.jpg"
content_type="application/octet-stream"
date=`date -R`
_signature="PUT\n\n${content_type}\n${date}\n${resource}"
signature=`echo -en ${_signature} | openssl sha1 -hmac ${s3_secret} -binary | base64`
curl -v -X PUT -T "${file}" \
-H "Host: $host" \
-H "Date: ${date}" \
-H "Content-Type: ${content_type}" \
-H "Authorization: AWS ${s3_key}:${signature}" \
https://$host${resource}
GET:
cd /Users/cniackz/Desktop/temporalnewdiretory
bucket=testing
file=arbol.jpg
host=play.min.io
s3_key='Q3AM3UQ867SPQQA43P2F'
s3_secret='zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG'
resource="/testing/arbol.jpg"
content_type="application/octet-stream"
date=`date -R`
_signature="GET\n\n${content_type}\n${date}\n${resource}"
signature=`echo -en ${_signature} | openssl sha1 -hmac ${s3_secret} -binary | base64`
curl -o ./arbol-2.jpg -v \
-H "Host: $host" \
-H "Date: ${date}" \
-H "Content-Type: ${content_type}" \
-H "Authorization: AWS ${s3_key}:${signature}" \
https://$host${resource}
Cesars-MacBook-Pro:temporalnewdiretory cniackz$ ls
arbol-2.jpg
Cesars-MacBook-Pro:temporalnewdiretory cniackz$ open .
Working with local minio instance without HTTPS
PUT
#! /usr/bin/bash
# ./minio-put.sh
# Usage :: ./minio-put.sh test file1 loalhost 9020 minioadmin minioadmin
bucket=$1
file=$2
host=$3
port=$4
s3_key=$5
s3_secret=$6
resource="/${bucket}/${file}"
content_type="application/octet-stream"
date=`date -R`
_signature="PUT\n\n${content_type}\n${date}\n${resource}"
signature=`echo -en ${_signature} | openssl sha1 -hmac ${s3_secret} -binary | base64`
curl -v -X PUT -T "${file}" \
-H "Host: $host" \
-H "Date: ${date}" \
-H "Content-Type: ${content_type}" \
-H "Authorization: AWS ${s3_key}:${signature}" \
http://$host:$port${resource}
$ mc alias ls m2
m2
URL : http://192.168.0.142:9020
AccessKey : minioadmin
SecretKey : minioadmin
API : s3v4
Path : auto
$ ./minio-put.sh test simple-home-office.jpg localhost 9020 minioadmin minioadmin
Note: Unnecessary use of -X or --request, PUT is already inferred.
* Trying 127.0.0.1:9020...
* Connected to localhost (127.0.0.1) port 9020 (#0)
> PUT /test/simple-home-office.jpg HTTP/1.1
> Host: localhost
> User-Agent: curl/7.85.0
> Accept: */*
> Date: Wed, 22 Mar 2023 22:13:49 +0530
> Content-Type: application/octet-stream
> Authorization: AWS minioadmin:UC1MApbYvp4/B/MavGdQOsX5vWw=
> Content-Length: 1036176
> Expect: 100-continue
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 100 Continue
* We are completely uploaded and fine
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Accept-Ranges: bytes
< Content-Length: 0
< Content-Security-Policy: block-all-mixed-content
< ETag: "c2c766bf0c610e8a5f97bee0b9be26ca"
< Server: MinIO
< Strict-Transport-Security: max-age=31536000; includeSubDomains
< Vary: Origin
< Vary: Accept-Encoding
< X-Amz-Id-2: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
< X-Amz-Request-Id: 174ECB787E14009B
< X-Content-Type-Options: nosniff
< X-Xss-Protection: 1; mode=block
< Date: Wed, 22 Mar 2023 16:43:49 GMT
<
* Connection #0 to host localhost left intact
$ mc ls m2/test
[2023-03-22 22:13:49 IST]1012KiB STANDARD simple-home-office.jpg
GET
#! /usr/bin/bash
# ./minio-get.sh
# Usage :: ./minio-get.sh test file1 loalhost 9020 minioadmin minioadmin
bucket=$1
file=$2
host=$3
port=$4
s3_key=$5
s3_secret=$6
resource="/${bucket}/${file}"
content_type="application/octet-stream"
date=`date -R`
_signature="GET\n\n${content_type}\n${date}\n${resource}"
signature=`echo -en ${_signature} | openssl sha1 -hmac ${s3_secret} -binary | base64`
curl -v -o ./get.${file} -X GET \
-H "Host: $host" \
-H "Date: ${date}" \
-H "Content-Type: ${content_type}" \
-H "Authorization: AWS ${s3_key}:${signature}" \
http://$host:$port${resource}
$ ./minio-get.sh test simple-home-office.jpg localhost 9020 minioadmin minioadmin
Note: Unnecessary use of -X or --request, GET is already inferred.
* Trying 127.0.0.1:9020...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Connected to localhost (127.0.0.1) port 9020 (#0)
> GET /test/simple-home-office.jpg HTTP/1.1
> Host: localhost
> User-Agent: curl/7.85.0
> Accept: */*
> Date: Wed, 22 Mar 2023 22:16:21 +0530
> Content-Type: application/octet-stream
> Authorization: AWS minioadmin:56uQHMvz1mADPalXHCbwn6M7Vro=
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Accept-Ranges: bytes
< Content-Length: 1036176
< Content-Security-Policy: block-all-mixed-content
< Content-Type: application/octet-stream
< ETag: "c2c766bf0c610e8a5f97bee0b9be26ca"
< Last-Modified: Wed, 22 Mar 2023 16:43:49 GMT
< Server: MinIO
< Strict-Transport-Security: max-age=31536000; includeSubDomains
< Vary: Origin
< Vary: Accept-Encoding
< X-Amz-Id-2: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
< X-Amz-Request-Id: 174ECB9BCFE70759
< X-Content-Type-Options: nosniff
< X-Xss-Protection: 1; mode=block
< Date: Wed, 22 Mar 2023 16:46:21 GMT
<
{ [32768 bytes data]
100 1011k 100 1011k 0 0 94.9M 0 --:--:-- --:--:-- --:--:-- 109M
* Connection #0 to host localhost left intact
$ ls get-simple-home-office.jpg
get-simple-home-office.jpg