无法使用curl将多个文件发送到send-anywhere.com

无法使用curl将多个文件发送到send-anywhere.com,curl,multipartform-data,crystal-lang,Curl,Multipartform Data,Crystal Lang,我试图在Crystal中构建一个CLI工具,以便从命令行使用send anywhere.com 发送multipart不是Crystal内置的,但在编写我自己的之前,我想我会尝试使用cURL,看看我应该如何制作它,但我甚至不能让它与cURL一起工作 问题是,当使用cURL发送多个文件时,他们的服务器只看到传入的一个文件,他们确实看到了总长度,但失败率为50%,因为他们只需要一个文件 最要命的是它在浏览器中工作,我打开了网络检查器,但我看不到与cURL请求的区别。 我试着将Expect头设置为10

我试图在Crystal中构建一个CLI工具,以便从命令行使用
send anywhere.com

发送multipart不是Crystal内置的,但在编写我自己的之前,我想我会尝试使用cURL,看看我应该如何制作它,但我甚至不能让它与cURL一起工作

问题是,当使用cURL发送多个文件时,他们的服务器只看到传入的一个文件,他们确实看到了总长度,但失败率为50%,因为他们只需要一个文件

最要命的是它在浏览器中工作,我打开了网络检查器,但我看不到与cURL请求的区别。 我试着将Expect头设置为100 continue,我比较了它们,但是我看不出什么可以使它与浏览器一起工作,而不是curl

这是我用cURL尝试的命令,结果都是一样的,服务器最终只看到1个文件传入,而不是2个

出于测试目的,我使用了一些通用许可文件的副本

curl -F file1=@LICENSE -F file2=@LICENSE1 https://...their.weblink...
我在inspector中看到Chrome在Content Disposition中将文件名命名为“file[]”,所以我自己也尝试过(结果相同):

我还使用
-H“Expect:100 continue”
尝试了这两个命令,结果相同

在这一点上,我发疯了,我想我应该自己试试,也许cURL做不好(在我看来不太可能,我做错事情的可能性更大)

因此,在从头开始编写之前,我尝试了一个电报机器人使用的实现,请参见:

这很简单,但我还是有同样的问题。仅识别第一个文件

注意:当只发送一个文件时,cURL和Crystal实现都可以正常工作

我快发疯了,正常工作的浏览器和其他两个有什么区别?我没有看到什么

我不是在寻找一个实现,只是希望有人指出我错过了什么,这将使多个文件正确识别

这只是出于教育目的,实际上这样做违反了 服务条款。它有一个文档化的API,您应该使用它 相反,在给定API密钥之后

正确地宣布
端点的文件数非常重要。整个流程如下所示:

#!/bin/bash

# First we need to get a device key by registering ourselves as a
# device. For that we need a profile name. We need to store the
# received cookie and send it with the subsequent request.
profilename="$(openssl rand -hex 6)"
curl -c .session -vL https://send-anywhere.com/web/device \
  -d "os_type=web" \
  -d "profile_name=$profilename" \
  -d "manufacturer=Linux" \
  -d "model_number=Firefox" \
  -d "app_version=48" \
  -d "device_language=en-US"

# We need to know the individual filesizes in bytes as well as
# the total size we're going to upload
file0name="foo.txt"
file0size="$(wc -c "$file0name" | cut -d ' ' -f 1)"
file1name="bar.txt"
file1size="$(wc -c "$file1name" | cut -d ' ' -f 1)"
filesize="$(echo "$file0size + $file1size" | bc)"

# Using that info and the cookie we got from the device key
# we can correctly announce our upload
key="$(curl -b .session -vL https://send-anywhere.com/web/key \
  -d "file[0][name]=$file0name" -d "file[0][size]=$file0size" \
  -d "file[1][name]=$file1name" -d "file[1][size]=$file1size" \
  -d "file_number=2" -d "file_size=$filesize")"

# We get some JSON back with the URL to send to the receiver
# and the URL to upload back
url="$(echo "$key" | ruby -rjson -e 'print JSON.parse($stdin.read)["link"]')"
upload_url="$(echo "$key" | ruby -rjson -e 'print JSON.parse($stdin.read)["weblink"]')"

echo
echo "------------------------------------------------------------"
echo "Receive 2 files of $filesize bytes at $url"
echo "------------------------------------------------------------"
echo

# And finally do the upload
curl -vL "$upload_url" \
  -F "file[]=@$file0name" \
  -F "file[]=@$file1name"
这只是出于教育目的,实际上这样做违反了 服务条款。它有一个文档化的API,您应该使用它 相反,在给定API密钥之后

正确地宣布
端点的文件数非常重要。整个流程如下所示:

#!/bin/bash

# First we need to get a device key by registering ourselves as a
# device. For that we need a profile name. We need to store the
# received cookie and send it with the subsequent request.
profilename="$(openssl rand -hex 6)"
curl -c .session -vL https://send-anywhere.com/web/device \
  -d "os_type=web" \
  -d "profile_name=$profilename" \
  -d "manufacturer=Linux" \
  -d "model_number=Firefox" \
  -d "app_version=48" \
  -d "device_language=en-US"

# We need to know the individual filesizes in bytes as well as
# the total size we're going to upload
file0name="foo.txt"
file0size="$(wc -c "$file0name" | cut -d ' ' -f 1)"
file1name="bar.txt"
file1size="$(wc -c "$file1name" | cut -d ' ' -f 1)"
filesize="$(echo "$file0size + $file1size" | bc)"

# Using that info and the cookie we got from the device key
# we can correctly announce our upload
key="$(curl -b .session -vL https://send-anywhere.com/web/key \
  -d "file[0][name]=$file0name" -d "file[0][size]=$file0size" \
  -d "file[1][name]=$file1name" -d "file[1][size]=$file1size" \
  -d "file_number=2" -d "file_size=$filesize")"

# We get some JSON back with the URL to send to the receiver
# and the URL to upload back
url="$(echo "$key" | ruby -rjson -e 'print JSON.parse($stdin.read)["link"]')"
upload_url="$(echo "$key" | ruby -rjson -e 'print JSON.parse($stdin.read)["weblink"]')"

echo
echo "------------------------------------------------------------"
echo "Receive 2 files of $filesize bytes at $url"
echo "------------------------------------------------------------"
echo

# And finally do the upload
curl -vL "$upload_url" \
  -F "file[]=@$file0name" \
  -F "file[]=@$file1name"


注:mutlipart应该很快进入标准库,见@JonneHaß耶,我知道我关注这个问题已经有一段时间了!但我甚至不确定它是否能解决我遇到的这个问题。我不了解这个网站,当我添加文件时它对我没有任何帮助(假设我尝试了正确的网站,而你只是忘记了域中的破折号)。@JonneHaß是的,我遇到了同样的问题只要打开inspector,你就会在控制台中看到许多被客户端阻止的错误,禁用adblock/ghostery以修复此问题。或者只是通过一个匿名窗口运行它。注意mutlipart应该很快就会进入标准库,请参阅@JonneHaß耶,我知道我关注这个问题已经有一段时间了!但我甚至不确定它是否能解决我遇到的这个问题。我不了解这个网站,当我添加文件时它对我没有任何帮助(假设我尝试了正确的网站,而你只是忘记了域中的破折号)。@JonneHaß是的,我遇到了同样的问题只要打开inspector,你就会在控制台中看到许多被客户端阻止的错误,禁用adblock/ghostery以修复此问题。或者只是通过一个不知名的窗口运行它。啊!我从未想过要查看上一个请求,因为它们工作得很好(是的,我有自己的API密钥)。我也不完全理解,但使用API(使用有效密钥)发送多个文件是否违反了他们的ToS?或者只发送文件而不使用API密钥?无论如何谢谢你!还有可能他们只是忘记了将这个添加到他们的API文档中:没有提到必须指定文件数!也可能不清楚,但我从一开始就在使用自己的API密钥。但是最后一步(上传到网络链接)不需要密钥,这就是为什么没有提到它的原因。它只需要执行注册设备和获取6位数的关键步骤。我写这篇文章是因为我使用了web应用程序的端点,而不是API。啊,好吧,它的工作原理是一样的,只是没有记录在他们的API页面中。谢谢啊!!我从未想过要查看上一个请求,因为它们工作得很好(是的,我有自己的API密钥)。我也不完全理解,但使用API(使用有效密钥)发送多个文件是否违反了他们的ToS?或者只发送文件而不使用API密钥?无论如何谢谢你!还有可能他们只是忘记了将这个添加到他们的API文档中:没有提到必须指定文件数!也可能不清楚,但我从一开始就在使用自己的API密钥。但是最后一步(上传到网络链接)不需要密钥,这就是为什么没有提到它的原因。它只需要执行注册设备和获取6位数的关键步骤。我写这篇文章是因为我使用了web应用程序的端点,而不是API。啊,好吧,它的工作原理是一样的,只是没有记录在他们的API页面中。谢谢