Invoke-RestMethod Загрузить ZIP-файл

Я пытаюсь загрузить файл в uri с помощью POST. Я как-то терплю неудачу. я получил помощь от

powershell invoke-restmethod multipart/form-data

но они загрузили текстовый файл.

Также работает команда curl:

curl -X POST "https://some.place.over.the.rainbow.com/api/v1/dataupdate" -H "accept: */*" -H "Authorization: Basic 123123123123" -F "file=@/c/updates/SomeFile.zip"   

В моем сценарии ps1 я пробовал следующее:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

$Headers = @{
    Authorization = "Basic 123123123123"
};

$FilePath = "C:\Users\asd\SomeFile.zip";
$Uri = 'ttps://some.place.over.the.rainbow.com/api/v1/dataupdate';
$LF = "`r`n";
$boundary = [System.Guid]::NewGuid().ToString(); 

$fileBytes = [System.IO.File]::ReadAllBytes($FilePath);
$fileEnc = [System.Text.Encoding]::GetEncoding('UTF-8').GetString($fileBytes);

$bodyLines = ( 
    "--$boundary",
    "Content-Disposition: form-data; name=`"file`"; filename=`"SomeFile.zip`"",
    $fileEnc,
    "--$boundary--$LF" 
) -join $LF

Invoke-RestMethod -Uri $Uri -Method Post -ContentType "multipart/form-data; boundary=`"$boundary`"" -Headers $Headers -Body $bodyLines

На стороне сервера я получаю

Servlet.service() for servlet [dispatcherServlet] in context with path [/...] threw exception [Request processing failed; nested exception is
 org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet request; 
 nested exception is java.io.IOException: org.apache.tomcat.util.http.fileupload.FileUploadException: 
 Header section has more than 10240 bytes (maybe it is not properly terminated)] with root cause
 org.apache.tomcat.util.http.fileupload.MultipartStream$MalformedStreamException: Header section has more than 10240 bytes (maybe it is not properly terminated)at 
 org.apache.tomcat.util.http.fileupload.MultipartStream.readHeaders(MultipartStream.java:523) 
 ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]at org.apache.tomcat.util.http.fileupload.FileUploadBase$FileItemIteratorImpl.findNextItem(FileUploadBase.java:880) 
 ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]at org.apache.tomcat.util.http.fileupload.FileUploadBase$FileItemIteratorImpl.<init>(FileUploadBase.java:845) 

Мне нужно выполнить его на машине с Windows, где, к сожалению, у меня нет завитка.

Ценю любую помощь


person kism3t    schedule 13.05.2019    source источник
comment
Посмотрите, будет ли это более полезным... stackoverflow.com/questions/25075010/   -  person postanote    schedule 13.05.2019
comment
Я попробовал подход по вашей ссылке, но я получаю другую ошибку, чем exceeded the limit for maxPostSize set on the associated connector, но на моем приложении весенней загрузки на стороне сервера я заранее установил spring.servlet.multipart.max-file-size=-1 spring.servlet.multipart.max-request-size=-1   -  person kism3t    schedule 15.05.2019
comment
попробуйте изменить кодировку с utf-8 на iso8859-1 $fileEnc = [System.Text.Encoding]::GetEncoding('UTF-8').GetString($fileBytes);   -  person ncowboy    schedule 21.06.2019