I'm attempting to POST a file to an API that requires the file to be GZip. The file uploads correctly (I can see the file on the website interface), but I get back an error of "The magic number in GZip header is not correct. Make sure you are passing in a GZip stream." when I ask the API to process it. Am I doing something wrong in the zipping? Something wrong in my posting?
SET PROCEDURE TO prog\wwAPI Addi
LOCAL lcZip
lcZIP = GZipCompressString(lcItemJSON)
STRTOFILE(lcZip, "item.json.gz")
* Upload it.
oHTTP2 = CREATEOBJECT("wwHTTP")
oHTTP2.cHTTPVerb = "PUT"
oHttp2.nHttpPostMode = 1
oHTTP2.AppendHeader("x-ms-blob-type", "blockblob")
oHttp2.AddPostKey("File", SYS(5) + CURDIR() + "item.json.gz", .t.)
lcReturn = oHTTP2.HttpGet(lcUploadURL)
How are you supposed to push the file to the server? Pretty sure the format you're using is not correct.
Is the data supposed to be in raw format? If so just send the raw text - not a post variable as you are. Set the content type to whatever the data format is:
oHttp2.ContentType = "application/json"
oHttp2.AddPostKey(lcZip)
This sends the raw data not a form variable.
If the data protocol multi-part form then you need to make sure the mode is set to 2.
More info here:
+++ Rick ---
The spec says to upload a file, but you were right -- just send the raw data. Huge thank you for pointing me in the right direction.
Here's the working code for anyone interested (this is for the Jet.com file upload for MerchantSkus):
oHTTP2 = CREATEOBJECT("wwHTTP")
oHTTP2.cHTTPVerb = "PUT"
oHttp2.cContentType = "application/json"
oHttp2.AddPostKey(lcZip)
oHTTP2.AppendHeader("x-ms-blob-type", "blockblob")
lcReturn = oHTTP2.HttpGet(lcUploadURL)