Following is being done: 1) Client requests a ZIP file from our server using an API call. 2) He provides a call back url which is an aspx program in the API request. 3) We create the ZIP file, using php CURL script upload the ZIP file to his aspx program.
The issue is, the ZIP file format changes (to SFX Zip archive) when the file gets uploaded on his server. If the same file is uploaded to our server using a simple php script the format remains unchanged. We are not sure if the issue is with the way we are uploading the file using CURL or if its with the way the client is saving the ZIP file on his server.
The CURL code is as following :
$download_file = "/tmp/test.zip";
$callBackUrl = "http://www.remoteurl/theclients_uploadcode.aspx";
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('file' => "@$download_file"));
curl_setopt($ch, CURLOPT_URL, $callBackUrl);
curl_exec($ch);
curl_close($ch);
The client provided the aspx code for saving the data:
private void SavePost()
{
HttpPostedData = ReadFully(this.Page.Request.InputStream);
Timestamp = DateTime.Now.ToString("MMddyyyy-hhmmss");
Timestamp = Timestamp.Replace("-", "").Replace(" ", "").Replace(":", "");
if (FileName.ToString() == string.Empty)
{
FileName = Timestamp;
}
if (FileName.Contains(".zip") == false)
{
FileName = FileName + ".zip";
}
tempFilePath = (tempFilePath + FileName);
Response.Write((tempFilePath + (" HttpPostedData:" + HttpPostedData)));
}
public static byte[] ReadFully(Stream input)
{
byte[] buffer = new byte[16 * 1024];
using (MemoryStream ms = new MemoryStream())
{
int read;
while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
{
ms.Write(buffer, 0, read);
}
return ms.ToArray();
}
}
Thanks in advance.