Best approach - Zip file uploads from Client to Server (plus hash value check)
See original GitHub issueHello Everyone, and Happy New Year when it comes at your local time zone! 😃
I am asking for advice for best approach how I should use this WatsonTcp package. I need to upload ZIP files, one file per day from a Client application to a Server application. At both ends I would like to use WatsonTcp. The size of the Zip files varies between 50-150 MBytes.
I am thinking about the following:
- I create a FileStream from the zip file in the following way at the Client side (i only show part of the code):
using (FileStream fss = new FileStream(zipFilePath, FileMode.Open, FileAccess.Read))
{
using (SHA256 mySHA256 = SHA256.Create())
{
byte[] hashValue = mySHA256.ComputeHash(fss);
Dictionary<object, object> metadata = new Dictionary<object, object>();
metadata.Add(MetaData.FileName, Path.GetFileName(zipFilePath));
metadata.Add(MetaData.FileSize, length);
metadata.Add(MetaData.UploadStarted, DateTime.Now);
metadata.Add(MetaData.CheckSum, hashValue);
SyncResponse resp = Client.SendAndWait(ClientTimeout, fss.Length, fss, metadata);
bool repliedHashOK = (bool)resp.Metadata[MetaData.CheckSumOK];
if (repliedHashOK) {}
else {}
}
}
- At the server side, I register for the Callback “private static SyncResponse SyncRequestReceived(SyncRequest req)”. Inside this, I should recalculate the hash value of the FileStream, compare to the Value of the MetaData.CheckSum Key, then set the MetaData.CheckSumOK accordingly before sending the SyncResponse back to the Client.
Question:
I need to create the ZIP file at the Server side if the hash values match. For this, what data element can I use in the “private static SyncResponse SyncRequestReceived(SyncRequest req)” callback method? The “req.Data” is a byte array, I guess this array contains the same data what was sent by the Client.SendAndWait() method in the form of a FileStream? So I can calculate hash on this byte array, and I should be able to create the zip file from the byte array, yes?
Thanks very much for help, and any suggestions how I should do this file transfer better! Best Regards,
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
Hi @bukkideme definitely nothing wrong with running your code controlling both a server instance and a client instance like you would need to do on PC #2. The nice thing is that most of the underlying TCP work is already taken care of for you. You could very easily just implement a proxy of sorts in #2 that would listen for incoming streams and send them to #3. The hard part will be dealing with errors, i.e. #3 goes down prior to a response being fully sent back to #2 (that would be sent back to #1). Best of luck to you.
Exactly 😃