Almost two days now, trying to upload a *.gzip (or *.gz) file to jet api. Below code uploads the file, but jet api says "Error parsing file: The magic number in GZip header is not correct. Make sure you are passing in a GZip stream."
function getCurlValue($filename, $contentType, $postname){
// PHP 5.5 introduced a CurlFile object that deprecates the old @filename syntax
// See: https://wiki.php.net/rfc/curl-file-upload
if (function_exists('curl_file_create')) {
return curl_file_create($filename, $contentType, $postname);
}
// Use the old style if using an older version of PHP
$value = "@{$filename};filename=" . $postname;
if ($contentType) {
$value .= ';type=' . $contentType;
}
return $value;
}
function curl_upload_test($file, $remote_url){
$filename = 'gzip-test.gz';
$cfile = getCurlValue($filename, 'application/x-gzip', $filename);
$data = array('file' => $cfile, 'method' => 'PUT');
$ch = curl_init();
$options = array( CURLOPT_URL => $remote_url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => $data['method'],
CURLOPT_HTTPHEADER => array(
'Accept:',
'Expect:',
'Content-Type: application/x-gzip',
'x-ms-blob-type: blockblob'
),
CURLINFO_HEADER_OUT => true, //Request header
CURLOPT_HEADER => 0, //Return header
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $data
);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
$header_info = curl_getinfo($ch,CURLINFO_HEADER_OUT);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($result, 0, $header_size);
$body = substr($result, $header_size);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return $httpcode;
}
I wen't through their documentation, and found jet api sample code for *.gzip file upload with C#.
///Url returned by GET /api/files/uploadToken
var url = "https://imupload.blob.core.windows.net/merchant-files/b21611714c8d4734a7686e86f7a8080d?sv=2014-02-14&sr=b&sig=05ssdgrshow383JVEmqk%2BDwrTlHqfEO16gApw%2BgK6%2F2k%3D&se=2014-12-02T17%3A13%3A16Z&sp=w";
var request = WebRequest.CreateHttp(url);
request.Method = "PUT";
request.Headers.Add("x-ms-blob-type:BlockBlob");
using (var stream = File.OpenRead(@"C:\temp\test.json"))
using(var zipped = new GZipStream(request.GetRequestStream(), CompressionMode.Compress))
stream.CopyTo(zipped);
request.GetResponse();
Any help on this highly appreciated.