I created a self-service .NET service that accepts binary downloads.
[ServiceContract]
public interface IBinaryService
{
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "up/file/{fileName}/{hash}")]
void FileUpload(string fileName, string hash, Stream fileStream);
When he receives a file, he first checks whether this file is already in the system, otherwise he transfers the file from the client and saves it:
public void FileUpload(string fileName, string hash, Stream fileStream)
{
string filebasedir = basedir + @"file\";
if (File.Exists(filebasedir + hash))
{
WebOperationContext.Current.OutgoingResponse.StatusCode =
System.Net.HttpStatusCode.Conflict;
return;
}
using(var fileToupload = new FileStream(
string.Concat(filebasedir, hash),
FileMode.Create))
{
fileStream.CopyTo(fileToupload);
}
If I go through the code, I see that the contents of the file are not broadcast until AFTER the server reads the parameters and decides if there is a conflict. I just need to somehow make the server not read the full content (which can be many megabytes). Exiting a method earlier using 'return' does not, unfortunately.
Is it possible?
source
share