Reputation: 137
So i'm kinda new to powershell and want to make a simple script that will upload the chosen file to anonyfiles. The thing i'm having problems with is uploading to the api i have managed to upload it through cmd but now i'm hoping i can do it through powershell.
The command i used to upload the files through cmd is:
curl -F "file=@C:\Eclips-Terminal\Websites.csv" https://api.anonfiles.com/upload
To re-state it:
URLS:
all help is welcome.
Upvotes: 1
Views: 2052
Reputation: 8868
In powershell curl
is an alias for Invoke-WebRequest
.
get-alias curl
CommandType Name Version Source
----------- ---- ------- ------
Alias curl -> Invoke-WebRequest
You can still run any executable in powershell that you can run in cmd, just specify the executable.
curl.exe -F "file=@C:\Eclips-Terminal\Websites.csv" https://api.anonfiles.com/upload?token=<YOUR API KEY>
You will notice text in red, that's not an error but rather the way curl.exe writes it's progress to stderr stream which in powershell shows up in red. I have no doubt there is a switch/parameter you can use on curl.exe to omit this progress output but a simple way is to pipe stderr to $null
.
curl.exe -F "file=@C:\Eclips-Terminal\Websites.csv" https://api.anonfiles.com/upload?token=<YOUR API KEY> 2>$null
Finally, if you capture the remaining output to a variable then you can extract your short url from it.
$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
Upvotes: 1