jclyo1's picture
updates
707c523
raw
history blame
807 Bytes
#!/usr/bin/env bash
set -e
FILE=$(readlink -f "$1")
FORMAT=$2
json_data=$(
curl -s https://api.steg.ai/upload \
-H "x-api-key: ${STEG_AI_API_KEY}" \
--data-raw '{ "name": "'$(basename "${FILE}")'", "content_type": "'$FORMAT'" }')
readarray -t fields < <(echo "${json_data}" | jq -r '.data.post_to.fields | keys[]')
media_id=$(echo "${json_data}" | jq -r '.data.media_id')
presigned_url=$(echo "${json_data}" | jq -r '.data.post_to.url')
# Iterate over the keys array and build the curl parameters
form_string=""
for field in "${fields[@]}"; do
value=$(echo "${json_data}" | jq -r --arg key "${field}" '.data.post_to.fields[$key]')
form_string+="--form ${field}=${value} "
done
curl -s --location --request POST ${presigned_url} ${form_string} --form "file=@${FILE}"
echo ${media_id}