Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to open/read local data from file/application

I was trying to run curl command using PowerShell.

below is the curl command

curl --location --request POST "controller/lttrouter/v1/TestResult/process-data-results/" --form "synthesisreport=@"C:\Users\subu\Desktop\testdemo\SynthesisReport.csv";type=text/csv" --form "createdBy=subu" --form "jiraStoryId=LT1235" --form "jiraTaskId=LT1236" --form "tag=demo-test"

Above curl is working on the Command Prompt.

I tried below PowerShell code

$CurlExecutable = "C:\curl-7.65.1-win64-mingw\bin\curl.exe"
$path="C:\Users\subu\Desktop\Test\SynthesisReport.csv"

Write-Host "CurlFile" $CurlFile
$CurlArguments = '--location','--request', 'POST', 
                 '"controller/lttrouter/v1/TestResult/process-data-results/"',
                 '--form', 'synthesisreport=@$path',
                 '--form', 'createdBy=subu',
                 '--form', 'jiraStoryId=LT1235',
                 '--form', 'jiraTaskId=LT1236',
                 '--form', 'tag=demo-test'

& $CurlExecutable @CurlArguments

I am getting below error

curl.exe : curl: (26) Failed to open/read local data from file/application
At line:13 char:1
+ & $CurlExecutable @CurlArguments
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (curl: (26) Fail...ile/application:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

Where I am doing the mistake, please suggest.

like image 686
Subrata Sarkar Avatar asked Jun 13 '19 09:06

Subrata Sarkar


1 Answers

Don't use splatting in this case, just pass the argument list ($ instead of @), properly add the quotes and make sure $path gets expanded:

$curlExecutable = "C:\curl-7.65.1-win64-mingw\bin\curl.exe"
$path = "C:\Users\subu\Desktop\Test\SynthesisReport.csv"

Write-Host "CurlFile" $curlExecutable
$curlArguments = "--location","--request", "POST", 
                 "`"controller/lttrouter/v1/TestResult/process-data-results/`"",
                 "--form", "`"synthesisreport=@`"$path`";type=text/csv`"",
                 "--form", "`"createdBy=subu`"",
                 "--form", "`"jiraStoryId=LT1235`"",
                 "--form", "`"jiraTaskId=LT1236`"",
                 "--form", "`"tag=demo-test`""

& $curlExecutable $curlArguments    
like image 70
mhu Avatar answered Sep 16 '22 11:09

mhu