0

I cannot POST a php form with two files in powershell

I search the equivalent of the bash command : /usr/bin/curl -F fichier1=@/path_to_file1 -F fichier2=@/path_to_file2\MyUrl.com

The Php form "formulaire" wait two parameters : "fichier1" type file and "fichier2" type file

I've tried to follow the resolution of What is the right way to POST multipart/form-data using curl? but i have the error message A parameter cannot be found that matches parameter name 'F' I've tried to use the Invoke-Method with -Infile parameter but it accepts only one string parameter and I can't pass my two files path Hère is my code :

$Uri = "//MyUrl.com/backups/uploadLogsVms.php"
$filePath="C:\backup_points.csv"
$filePath2="C:\PROTECTED_VMS_JOB_SCHEDULE_2018_12_10.csv"
curl -v -F fichier1=@"$filePath" -F fichier2=@"$filePath2"

I expected to fill the form below and press the button boutEnvoyer with a powershell script:

<body>
<form name='formulaire' id='formulaire' method='post' action='/backups/uploadLogsVms.php' enctype='multipart/form-data'>
     <input type='file' name='fichier1' id='fichier' size='60' /><br />
     <input type='file' name='fichier2' id='fichier' size='60' /><br />
     <input type='submit' class='bouton' id='boutEnvoyer' value='Envoyer' />
</form>
</body></html>

witch is equivalent to my bash command /usr/bin/curl -F fichier1=@/path_to_file1 -F fichier2=@/path_to_file2 http://MyUrl.com/backups/uploadLogs.php

1 Answer 1

0

Ok I've found the solution

I've downloaded powershell 6.2 version powershell 6.2 preview and now the -Form parameter works !

and I correct my code to

 $Uri = 'http://MyUrl.com/backups/uploadLogsVms.php'
$Form = @{
    fichier1     = Get-Item -Path 'C:\users\ADM_2N\Desktop\PROTECTED_VMS_JOB_SCHEDULE_2018_12_10.csv'
    fichier2     = Get-Item -Path 'C:\users\adm_2n\Desktop\backup_points.csv'

}
$Result = Invoke-RestMethod -Uri $Uri -Method Post -Form $Form
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.