首页 > 解决方案 > 如何使用 powershell 将文件上传到匿名文件

问题描述

所以我对powershell有点陌生,想制作一个简单的脚本,将所选文件上传到anonyfiles。我遇到的问题是上传到我已经设法通过cmd上传的api,但现在我希望我可以通过powershell来完成。

我用来通过cmd上传文件的命令是:

curl -F "file=@C:\Eclips-Terminal\Websites.csv" https://api.anonfiles.com/upload

重新声明它:

网址:

欢迎所有帮助。

标签: powershellfile-uploadupload

解决方案


在 powershellcurl中是Invoke-WebRequest.

get-alias curl

CommandType     Name                                               Version    Source                   
-----------     ----                                               -------    ------                   
Alias           curl -> Invoke-WebRequest

您仍然可以在 powershell 中运行任何可以在 cmd 中运行的可执行文件,只需指定可执行文件即可。

curl.exe -F "file=@C:\Eclips-Terminal\Websites.csv" https://api.anonfiles.com/upload?token=<YOUR API KEY>

您会注意到红色文本,这不是错误,而是 curl.exe 将其进度写入 stderr 流的方式,在 powershell 中显示为红色。我毫不怀疑您可以在 curl.exe 上使用一个开关/参数来省略此进度输出,但一种简单的方法是将 stderr 传输到$null.

curl.exe -F "file=@C:\Eclips-Terminal\Websites.csv" https://api.anonfiles.com/upload?token=<YOUR API KEY> 2>$null

最后,如果您将剩余的输出捕获到变量中,那么您可以从中提取短网址。

$output = curl.exe -F "file=@C:\Eclips-Terminal\Websites.csv" https://api.anonfiles.com/upload?token=<YOUR API KEY> 2>$null

($output | ConvertFrom-Json).data.file.url.short

推荐阅读