为什么这个 curl 命令 return 意外的 EOF

Why does this curl command return Unexpected EOF

我对 Bash 和 cURL 有点陌生,无法理解为什么这个 Bash 文件不会 运行 而不抛出 Unexpected EOF 错误。

此 cURL 命令应该以 20 MB 的块将大文件(在下面的示例脚本中,介于 300 和 400 MB 之间)上传到存储服务。上传所有 MB 后,第二个命令 "completes" 上传。两个命令使用相同的 GUID。

里面 upload-bits.sh:

#!/bin/sh
for i in {0..20}; do
curl -X POST \
  https://community.<company>.com/api.ashx/v2/cfs/temporary.json \
  -H 'Rest-User-Token: 12345' \
  -F UploadContextId=21f23109-aac2-44ef-8b89-c0f62e67da4d \
  -F FileName='file.zip' \
  -F TotalChunks=20 \
  -F CurrentChunk=$i \
  -F 'file=@file.zip'
done

Bash 脚本抛出 Unexpected EOF 错误。我在没有脚本的 Bash 部分的情况下单独尝试了 cURL 命令,并将 CurrentChunk 替换为 01 但没有成功。我还使用了脚本验证器,确认脚本没有问题。我还 运行 dos2unix 解决了行尾问题。

我还不能使用第二个脚本,因为第一个脚本没有用,但如果我没有很好地解释所需的整个过程,我会发布它以供参考。

complete-upload.sh:

curl -X POST \
  https://community.<company>.com/api.ashx/v2/media/371/files.json \
  -H 'Rest-User-Token: 12345' \
  -F 'Name=file.zip' \
  -F ContentType=application/zip \
  -F FileName='file.zip' \
  -F FileUploadContext=21f23109-aac2-44ef-8b89-c0f62e67da4d

如果有任何提示或见解,我将不胜感激。谢谢。

根据传递给 curl 的参数判断,服务器需要分块数据。

但是 curl 命令将整个文件发送了 20 次。

查看 https://community.telligent.com/community/10/w/api-documentation/61481/upload-cfs-rest-endpoint 处 CurrentChunk 的定义,也许像这样的修改会起作用:

#!/bin/bash

# using GNU split options will make arithmetic simpler
# with -d, we may get numbers like 09 which are invalid octal
# start from 101 if CurrentChunk is one-based
# start from 100 if CurrentChunk is zero-based
split -b20M -a3 --numeric-suffixes=101 file.zip part.

partlist=( part.* )
numparts=${#partlist[@]}

for part in ${partlist[@]}; do
  i=$(( ${part##*.}-100 ))
  curl -X POST \
    https://community.<company>.com/api.ashx/v2/cfs/temporary.json \
    -H 'Rest-User-Token: 12345' \
    -F UploadContextId=21f23109-aac2-44ef-8b89-c0f62e67da4d \
    -F FileName='file.zip' \
    -F TotalChunks=$numparts \
    -F CurrentChunk=$i \
    -F 'file=@'$part
done

rm ${partlist[@]}