GitLab API:如何将大型二进制文件作为 base64 与其他键=值一起放置

GitLab API: How to PUT a large binary file as base64 together with other key=values

我需要使用 Gitlab API 发送带有 curl (v.7.35.0) 的 PUT 请求,其中包含一些 key=value 参数. Key content 需要是二进制文件内容。所以我需要将它作为 base64 发送,但我之前已经失败了。然而,1.2MB 的大文件内容是我必须使用 stdin 的原因,因为 curl 和其他语法抱怨 URI / 参数列表太大。

https://unix.stackexchange.com/questions/174350/curl-argument-list-too-long那里得到了一些意见 .但是对于 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

curl 的常用替代品也适用于我。

终于让它与这个一起工作:

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