Cirrious.MvvmCross.Plugins.Network.Rest.MvxMultiPartFormRestRequest.UploadStreams C# (CSharp) Method

UploadStreams() protected method

protected UploadStreams ( Stream stream ) : void
stream Stream
return void
        protected virtual void UploadStreams(Stream stream)
        {
            if (StreamsToSend == null || StreamsToSend.Count == 0)
                return;

            byte[] boundarybytes = System.Text.Encoding.UTF8.GetBytes("\r\n--" + Boundary + "\r\n");

            const string fileHeaderTemplate =
                "Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\nContent-Type: {2}\r\n\r\n";
            foreach (var toSend in StreamsToSend)
            {
                stream.Write(boundarybytes, 0, boundarybytes.Length);
                string header = string.Format(fileHeaderTemplate, toSend.FieldName, toSend.FileName, toSend.ContentType);
                byte[] headerbytes = System.Text.Encoding.UTF8.GetBytes(header);
                stream.Write(headerbytes, 0, headerbytes.Length);
                toSend.WriteTo(stream);
            }
        }
    }