File size: 883 Bytes
707c523
 
19cedcb
 
 
 
 
 
707c523
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env bash

if [ "$TRUEPIC_DEBUG" = "2" ]; then
  set -xeo pipefail
else
  set -eo pipefail
fi

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}