Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var provider = new MultipartMemoryStreamProvider();
- await Request.Content.ReadAsMultipartAsync(provider);
- foreach (var file in provider.Contents)
- {
- var filename = file.Headers.ContentDisposition.FileName.Trim('"');
- var buffer = await file.ReadAsByteArrayAsync();
- // Doing stuff with the file here
- }
- $apiKey=$args[0]
- Write-Host "Using API Key: $apiKey"
- $fileId=$args[1]
- Write-Host "Using File ID: $fileId"
- $sourceFile=$args[2]
- Write-Host "Using File: $sourceFile"
- $baseUrl = "http://localhost:23857/api"
- $url = "$baseUrl/file/$fileId/version"
- $fileBin = [IO.File]::ReadAllBytes($sourceFile)
- $computer= $env:COMPUTERNAME
- $enc = [System.Text.Encoding]::GetEncoding("iso-8859-1")
- $fileEnc = $enc.GetString($fileBin)
- $boundary = [System.Guid]::NewGuid().ToString()
- $LF = "`n"
- $bodyLines = (
- "--$boundary",
- "Content-Disposition: form-data; name=`"filename.txt`"$LF", # filename= is optional
- $fileEnc,
- "--$boundary",
- "Content-Disposition: form-data; name=`"computer`"$LF",
- $computer,
- "--$boundary--$LF"
- ) -join $LF
- try {
- # Returns the response gotten from the server (we pass it on).
- #
- Invoke-RestMethod -Uri $url -Method Post -ContentType "multipart/form-data; boundary=`"$boundary`"" -TimeoutSec 120 -Body $bodyLines -Headers @{"ApiKey"=$apiKey}
- }
- catch [System.Net.WebException] {
- Write-Error( "FAILED to reach '$URL': $_" )
- throw $_
- }
- Unexpected end of MIME multipart stream. MIME multipart message is not complete.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement