1

I am trying to use the Hashicorp Atlas restful api to upload box files into but I am running into problems when uploading large files.

I am currently using the following command which works with small files like 100mb but most box files are well over 4GB where I start to see the problem:

$Filename = "c:\box\mybox.box"
$uploadpath = "https://archivist.hashicorp.com/v1/object/example"
$Timeout = 86400 #24 hours
Invoke-RestMethod -Uri $uploadPath -Method Put -InFile $Filename -TimeoutSec $Timeout -ContentType "multipart/form-data"

The error:

Invoke-RestMethod : The underlying connection was closed: An unexpected error occurred on a send.
At C:\Program Files\WindowsPowerShell\Modules\atlasbox\1.1.15\AtlasBox.psm1:642 char:5
+     Invoke-RestMethod -Uri $uploadPath -Method Put -InFile $Filename  ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

If I use CURL command as per the documentation it works fine.

curl -X PUT --upload-file /path/to/my.box https://archivist.hashicorp.com/v1/object/example

Any idea how to make Invoke-RestMethod behave the same way curl does?

I can't take a dependency on curl because not all systems I run this on will have WSL installed and no curl.

Documentation for Atlas API is here: https://atlas.hashicorp.com/help/api/vagrant/box-providers

Daniel Mann
  • 57,011
  • 13
  • 100
  • 120
Wil
  • 534
  • 4
  • 18

1 Answers1

0

Looks like it might be getting weird on the SSL cert? I would try some of the recommendations here to start with, definitely an oddity specific to those cmdlets though:

Powershell v3 Invoke-WebRequest HTTPS error

Community
  • 1
  • 1
scrthq
  • 1,039
  • 11
  • 17
  • this is only valid if you have not done this `[System.Net.ServicePointManager]::ServerCertificateValidati‌​onCallback = {$true}` – Ranadip Dutta May 03 '17 at 04:38
  • After adding the solution from that thread I now get: Invoke-RestMethod : Exception of type 'System.OutOfMemoryException' was thrown. At C:\Program Files\WindowsPowerShell\Modules\atlasbox\1.1.21\AtlasBox.psm1:691 char:5 + Invoke-RestMethod -Uri $uploadPath -Method Put -InFile $Filename ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Invoke-RestMethod], OutOfMemoryException + FullyQualifiedErrorId : System.OutOfMemoryException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand – Wil May 03 '17 at 04:52