I need to use the Gitlab API to send a PUT-request with curl (v.7.35.0) that holds some key=value
parameters. Key content
needs to be a binary file content. So I need to send it as base64, but I already fail before. However the big file content 1.2MB is the reason why I have to use stdin as curl with other syntax was complaining of too large URI / argument lists.
Took some input from https://unix.stackexchange.com/questions/174350/curl-argument-list-too-long . But still a bit lost with the combination of arguments in curl.
DATA="{
\"author_email\": \"autoupdate-geoip@company.com\",
\"author_name\": \"Autoupdater GeoIp\",
\"branch\": \"${BRANCH_NAME}\",
\"content\": \"this-should-be-file-content-of-GeoIP.dat\",
\"commit_message\": \"Update GeoIP database\"
\"encoding\": \"base64\"
}"
curl -X PUT -G "${GEOIP_URL}" \
--header "PRIVATE-TOKEN: ${TOKEN}" \
--header "Content-Type: application/json" \
--data-urlencode @- <<EOF
"${DATA}"
EOF
Common alternatives to curl would also work for me.
Finally got it to work with this:
base64 --wrap 0 GeoIP.dat > GeoIP.dat.base64
curl -vvvv -X PUT \
--header "PRIVATE-TOKEN: ${TOKEN}" \
--data-urlencode "author_email=autoupdate-geoip@company.com" \
--data-urlencode "author_name=Autoupdater GeoIP" \
--data-urlencode "branch=${BRANCH_NAME}" \
--data-urlencode "commit_message=Autoupdate GeoIP Database" \
--data-urlencode "encoding=base64" \
--data-urlencode "file_path=some/path/geoip/GeoIP.dat" \
--data-urlencode content@GeoIP.dat.base64 \
"${GEOIP_URL}" | python -m json.tool