Bash script to upload files to minio object storage using curl Rumi, November 6, 2026 #!/bin/bash # Configuration ACCESS_KEY="XXXXXXXXXXXXX" SECRET_KEY="YYYYYYYYYYYYYY" MINIO_HOST="api.castorage1.obs.platform.servermart.net" BUCKET="orangebd" FILE_PATH=$1 # Pass the filename as an argument if [ -z "$FILE_PATH" ]; then echo "Usage: $0 <file-path>" exit 1 fi if [ ! -f "$FILE_PATH" ]; then echo "Error: File '$FILE_PATH' does not exist." exit 1 fi FILE_NAME=$(basename "$FILE_PATH") RESOURCE="/${BUCKET}/${FILE_NAME}" CONTENT_TYPE="application/octet-stream" DATE=$(date -R) # Construct the string to sign STRING_TO_SIGN="PUT\n\n${CONTENT_TYPE}\n${DATE}\n${RESOURCE}" # Calculate the signature using OpenSSL SIGNATURE=$(printf "$STRING_TO_SIGN" | openssl dgst -sha1 -hmac "$SECRET_KEY" -binary | openssl enc -base64) echo "Starting upload of $FILE_NAME to MinIO API..." # Create a temporary file to capture the server's actual response body RESPONSE_FILE=$(mktemp) # ২. curl কমান্ডে "https://" ব্যবহার করা হয়েছে Force SSL রিডাইরেকশন এড়াতে curl -X PUT -T "$FILE_PATH" \ -# \ -H "Host: ${MINIO_HOST}" \ -H "Date: ${DATE}" \ -H "Content-Type: ${CONTENT_TYPE}" \ -H "Authorization: AWS ${ACCESS_KEY}:${SIGNATURE}" \ "https://${MINIO_HOST}${RESOURCE}" \ -o "$RESPONSE_FILE" \ -w "\nHTTP Status: %{http_code}\n" 2>&1 | tr '\r' '\n' | awk ' BEGIN { printf "Progress: 0%%" } /##/ { match($0, /[0-9]+(\.[0-9]+)?%/); if (RLENGTH > 0) { pct = substr($0, RSTART, RLENGTH); printf "\rProgress: %s", pct; } } /HTTP Status:/ { print "\n" $0 } ' # If the upload failed, show the response body error from MinIO if [ -s "$RESPONSE_FILE" ]; then echo "--- Server Response Details ---" cat "$RESPONSE_FILE" echo "" fi rm -f "$RESPONSE_FILE" Administrations Scripts