powershell - 如何使用 powershell 将文件上传到匿名文件
问题描述
所以我对powershell有点陌生,想制作一个简单的脚本,将所选文件上传到anonyfiles。我遇到的问题是上传到我已经设法通过cmd上传的api,但现在我希望我可以通过powershell来完成。
我用来通过cmd上传文件的命令是:
curl -F "file=@C:\Eclips-Terminal\Websites.csv" https://api.anonfiles.com/upload
重新声明它:
- 上传文件到 anonfiles ( https://anonfiles.com/ )
- 如果可能,将输出过滤为只有短 url。
网址:
欢迎所有帮助。
解决方案
在 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
推荐阅读
- javascript - 如何将 CodeSandbox proyecto 转换为 React 生产应用程序?
- python - Sequential'对象在保存keras模型时没有属性'output_names'
- java - 在 com.example.u.locationtracker.MainActivity.onCreate(MainActivity.java:39)
- jquery - 将选择器样式作为脉冲动画应用于元素
- php - 如何从 Azuracast API json 输出中获取 PHP 数据?
- django - 我无法在数据库中显示保存的图像
- python - 无论如何用openpyxl的公式刷新所有单元格?
- javascript - 检查数据是否等于 Firebase 上的某个值
- binary - 这是下溢的情况吗?
- sql - 在 R 中查询撇号