Search code examples
httpmultipart

Add zip to a http post request


How do you add a zip to a post request multipart/form-data?

The above uploads the zip, but when I download it it unzip to a .cpgz and if I unizp that it creates a .zip, and just cycles.


Solution

  • Change the Content-Disposition header to specify a filename that matches the actual name of the file you are uploading. You should also be setting the Content-Type to either application/zip or application/x-zip-compressed so the server knows the uploaded data is a zip file.

    $bytes = Get-Content "C:\Users\User\Test.zip" -Encoding Byte -ReadCount 0
    $parameters = "
    --$boundary
    Content-Disposition: form-data; name=`"file`"; filename=`"Test.zip`"
    Content-Type: application/x-zip-compressed
    Content-Transfer-Encoding: binary
    
    $bytes
    --$boundary--"