ghanna228715 (Community Member) asked a question.

Anyone have a functioning sample of invoking uploadfile.do using powershell? Without the C# or Java API wrapper?

I am using this, which works for all of the other API calls that I've tried, but does not work for uploadfile.do:

 

$pwd = ConvertTo-SecureString $apiUserPassword -AsPlainText -Force

$cred = New-Object System.Management.Automation.PSCredential ($apiUser, $pwd)

$postParams = @{app_id=$applicationId;sandbox_id=$sandboxId;file="@"+$zipOutputFile}

$response = Invoke-WebRequest https://analysiscenter.veracode.com/api/5.0/uploadfile.do -Method POST -Credential $cred -Body $postParams

 

 


  • Hi @ghanna228715 (Community Member)​ , thank you for your question. I am sorry that we haven't got you a response yet. I'm reaching out to our Application Security Consultant team regarding your question. Stay tuned while the team have a chance to check out your thread and respond. Please update this thread if you have made any progress or have an update to share with us. Thank you, and welcome to the Veracode Community!

    Expand Post
  • Hi @ghanna228715 (Community Member)​ ,

     

    The uploadfile.do API requires a file as well as form data to be submitted in a multipart HTTP request. Unfortunately, the Powershell Invoke-WebRequest cmdlet doesn't have support this natively so you have to format it yourself like so:

     

    $apiUserPassword = "example"

    $apiUser = "example"

    $FilePath = "C:\temp\upload.zip"

    $FileName = "upload.zip"

    $appId = "493537"

    $URL = "https://analysiscenter.veracode.com/api/5.0/uploadfile.do"

     

    $pwd = ConvertTo-SecureString $apiUserPassword -AsPlainText -Force

    $cred = New-Object System.Management.Automation.PSCredential ($apiUser, $pwd)

     

    $fileBytes = [System.IO.File]::ReadAllBytes($FilePath);

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

    $boundary = [System.Guid]::NewGuid().ToString(); 

    $LF = "`r`n";

     

    $bodyLines = (

      "--$boundary",

      "Content-Disposition: form-data; name=`"app_id`"$LF",

      $appId,

      "--$boundary",

      "Content-Disposition: form-data; name=`"file`"; filename=`"$FileName`"",

      "Content-Type: application/octet-stream$LF",

      $fileEnc,

      "--$boundary--$LF" 

    ) -join $LF

     

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

    $response = Invoke-WebRequest -Verbose -Credential $cred -Uri $URL -Method POST -ContentType "multipart/form-data; boundary=`"$boundary`"" -Body $bodyLines

     

    $response.Content

     

    Please let me know if this does not answer your question.

     

    Thank you,

    Boy Baukema, Veracode Application Security Consultant.

    Expand Post
  • Johnathan Howell-Zobel (Community Member)

    Late response, but maybe it'll save someone else some time. Veracode wants this encoded using ISO-8859-1, not UTF-8. Be sure to replace that section.

     

    $fileEnc = [System.Text.Encoding]::GetEncoding(''ISO-8859-1').GetString($fileBytes);

Topics (1)

No articles found
Loading

Ask the Community

Get answers, share a use case, discuss your favorite features, or get input from the community.