如何从 shell 脚本上传文件到 cloudinary?

How to upload files to cloudinary from shell script?

我正在尝试编写一个 shell 脚本来使用这样的 cURL 将编码为 base64 的文件上传到 cloudinary

#!/bin/bash

timestamp=$(date +%s)

apiSecret=

fileName=

data="api_key=679764637516936&file=$(base64 -w 0 $fileName)&timestamp=${timestamp}"

datatobehashed="timestamp=${timestamp}$apiSecret"

hash=$(echo ${datatobehashed} | sha1sum | awk '{print }')

curl -v "https://api.cloudinary.com/v1_1/zolatech/raw/upload --data \"${data}&signature=${hash}\""

echo ""

但它 returns 400 Bad Request 具有以下响应 {"error":{"message":"Invalid Signature 55683272b2d893c0d140af596a01d23977ede889. String to sign - 'timestamp=1484757367'."}}

所以我没有正确使用API吗?我的代码有问题吗?

哈希未正确回显,导致预期的 sha1 不匹配:

hash=$(echo -n ${datatobehashed} | sha1sum | awk '{print }')

您应该使用 echo -n,否则您将以尾随的换行符和错误的散列结尾。

echo-n

-n Do not print the trailing newline character.

GNU Bash : echo invocation