Difference between SendToZip and C# CreateFromDirectory zipfile

126 Views Asked by At

I am using RestSharp to send a POST request, the POST request contains a zip file along with the following headers:

        request.AddParameter("username", this.username, ParameterType.GetOrPost);
        request.AddParameter("userid", this.userid, ParameterType.GetOrPost);
        request.AddParameter("projectid", this.projectid, ParameterType.GetOrPost);
        //add the file
        request.AddFile("os_serverpackage", this.filelocation);
        request.AlwaysMultipartFormData = true;

In C# I am sending the request synchronously.

The file is making it to the server, we can see it coming through, so we don't think it is a RestSharp issue.

The problem we are having is the zip file is not being properly handled by our server (which is a node-backed server built on an ubuntu machine).

So we think the problem is the way we're using C# libraries to create the zip file.

The problem is when I send the same document as a zip file which was created with the sendToZip functionality on the desktop (windows) it works. However when I create the zip using C#'s native System.IO.Compression.ZipFile.CreateFromDirectory method to create the zip file, the server fails to respond.

What is the difference between the two?

I am using C#'s native System.IO.Compression.ZipFile.CreateFromDirectory method to create the zip file.

We're not experts on zip and compression, or using .NET to compress files, but we've done some basic troubleshooting. When we open one of these zip files on a Mac (a *nix machine of sorts), that originated from our .NET compression, we run into a problem where the zip is turned into a CPGZ and things look odd as outlined in this link http://osxdaily.com/2013/02/13/open-zip-cpgz-file/.

Another option we have is to change the way our node server handles the zip files. The server at the receiving end of the POST request is using adm-zip to extract the zip file.

Do any compression experts have any tips on ways to leverage these libraries to ensure that our zip file works cross platform?

1

There are 1 best solutions below

1
On

Seems to me that you're missing this (caveat: I'm not familiar with RestSharp):

request.AddHeader("Content-Type", "application/zip, application/octet-stream");

I know that Linux servers tend to be fussy about correct Content-Type HTTP headers and if you don't set it correctly then it won't be seen. At the very least you should use something like Fiddler2 to see if your messages are being transmitted correctly