base64在curl上下文中的转换

xxb16uws  于 5个月前  发布在  其他
关注(0)|答案(1)|浏览(60)

我想通过signal-mail发送一条消息和附件。
我通过bbernhard/signal-rest-api成功设置了docker一个容器,使用curl-statement正常发送消息,语句如下:

curl -X POST -H "Content-Type: application/json" -d '{\"message\": \"Hello World!\", \"number\": \"+490000000\", \"recipients\": [\"+4900000000"]}' 'http://localhost:48080/v2/send'

字符串
邮件将被发送给一个或多个收件人。也适用于一个组的groupID。
问:如何添加JPG等附件?
如果我将\"base64_attachments\": [\"${ENCODED_IMAGE}")\"]添加到语句中,则会得到错误消息{"error":"Couldn't process request - invalid request"}
完整的bash脚本看起来像:

#!/bin/bash

INPUT_FILE="/path/to/file/IMG_5098.JPG"

TMPFILE=$(mktemp)

base64 "${INPUT_FILE}" --wrap=0 > "${TMPFILE}"

ENCODED_IMAGE=$(cat "${TMPFILE}")

curl -X POST -H "Content-Type: application/json" -d '{\"message\": \"Hello World!\", \"base64_attachments\": [\"${ENCODED_IMAGE}")\"], \"number\": \"+4900000\", \"recipients\": [\"+4900000000\"]}' 'http://localhost:48080/v2/send'

rm "${TMPFILE}"


我期待着图像和信息的传递

gc0ot86w

gc0ot86w1#

我也遇到了同样的问题。下面是我如何通过Docker终端发送文件的:

TMPFILE="$(base64 SignalsPictures/flow.png)" && echo '{"message": "Test message", "base64_attachments": ["'"$TMPFILE"'"], "number": "+123456789012", "recipients": ["group.e..0="]}' | curl -X POST -H "Content-Type: application/json" -d @- 'http://localhost:8080/v2/send'

字符串

相关问题