Last active
October 30, 2024 16:18
-
-
Save JustinTimperio/7c7115f87b775618637d67ac911e595f to your computer and use it in GitHub Desktop.
Upload a File to Minio with Curl and Zero External Libraries or Programs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env sh | |
# Example: ./upload_to_minio example.url.com username password bucket-name internal/minio/path /absolute/path/file.txt.zst | |
if [ -z $1 ]; then | |
echo "You have NOT specified a MINIO URL!" | |
exit 1 | |
fi | |
if [ -z $2 ]; then | |
echo "You have NOT specified a USERNAME!" | |
exit 1 | |
fi | |
if [ -z $3 ]; then | |
echo "You have NOT specified a PASSWORD!" | |
exit 1 | |
fi | |
if [ -z $4 ]; then | |
echo "You have NOT specified a BUCKET!" | |
exit 1 | |
fi | |
if [ -z $5 ]; then | |
echo "You have NOT specified a UPLOAD PATH!" | |
exit 1 | |
fi | |
if [ -z $6 ]; then | |
echo "You have NOT specified a UPLOAD FILE!" | |
exit 1 | |
fi | |
# User Minio Vars | |
URL=$1 | |
USERNAME=$2 | |
PASSWORD=$3 | |
BUCKET=$4 | |
FILE_NAME=$(basename $6) | |
OBJ_PATH="/${BUCKET}/$5/${FILE_NAME}" | |
# Static Vars | |
DATE=$(date -R --utc) | |
CONTENT_TYPE='application/zstd' | |
SIG_STRING="PUT\n\n${CONTENT_TYPE}\n${DATE}\n${OBJ_PATH}" | |
SIGNATURE=`echo -en ${SIG_STRING} | openssl sha1 -hmac ${PASSWORD} -binary | base64` | |
curl --silent -v -X PUT -T "${FILE}" \ | |
-H "Host: $URL" \ | |
-H "Date: ${DATE}" \ | |
-H "Content-Type: ${CONTENT_TYPE}" \ | |
-H "Authorization: AWS ${USERNAME}:${SIGNATURE}" \ | |
https://$URL${OBJ_PATH} |
Does not work for me: with --utc
I get AWS authentication requires a valid Date or x-amz-date header
and without it The request signature we calculated does not match the signature you provided
(Trying to send a file to minIO ver. 2019-03-20T22:38:47Z, maybe the version is just too old for this script)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I propose to do
set -eu
at the beginning and adjusting${FILE}
in line 50 which is unbound. Finally it should read »an UPLOAD« to be correct.