-
Notifications
You must be signed in to change notification settings - Fork 0
/
.env
39 lines (35 loc) · 1.41 KB
/
.env
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
UPLOAD = $FilePath = "PATH_TO_YOURFILE"
$Uri = "http://localhost:8080/upload"
$fileName = [System.IO.Path]::GetFileName($FilePath)
$fileContent = [System.IO.File]::ReadAllBytes($FilePath)
$boundary = [System.Guid]::NewGuid().ToString()
$bodyLines = @(
"--$boundary",
"Content-Disposition: form-data; name=`"file`"; filename=`"$fileName`"",
"Content-Type: application/octet-stream",
"",
[System.Text.Encoding]::Default.GetString($fileContent),
"--$boundary--"
)
$body = $bodyLines -join "`r`n"
$bytes = [System.Text.Encoding]::Default.GetBytes($body)
$webRequest = [System.Net.HttpWebRequest]::Create($Uri)
$webRequest.Method = "POST"
$webRequest.ContentType = "multipart/form-data; boundary=$boundary"
$webRequest.ContentLength = $bytes.Length
$stream = $webRequest.GetRequestStream()
$stream.Write($bytes, 0, $bytes.Length)
$stream.Close()
$response = $webRequest.GetResponse()
$reader = New-Object System.IO.StreamReader($response.GetResponseStream())
$result = $reader.ReadToEnd()
Write-Host $result
DOWNLOAD = "$FileName = "YOUR_FILE_NAME"
$Uri = "http://localhost:8080/download/$FileName"
$OutputPath = "C:\path\to\save\downloaded_file.txt"
Invoke-WebRequest -Uri $Uri -OutFile $OutputPath"
LIST = "$Uri = "http://localhost:8080/list"
Invoke-RestMethod -Uri $Uri -Method Get"
DELETE = "$FileName = "YOUR_FILE_NAME"
$Uri = "http://localhost:8080/delete/$FileName"
Invoke-RestMethod -Uri $Uri -Method Delete"