Beispiel #1
0
 private void StartMultipartFile(string name, string s)
 {
     if (IsMultipart && File.Exists(s))
     {
         s = Path.GetFileName(s);
         if (string.IsNullOrEmpty(name))
         {
             name = Path.GetFileNameWithoutExtension(s);
         }
         SendStream.Write(MultiPart.Boundarybytes, 0, MultiPart.Boundarybytes.Length);
         var header      = string.Format(MultiPart.HeaderTemplate, name, s, MimeMapping.GetMimeMapping(s));
         var headerbytes = Encoding.UTF8.GetBytes(header);
         SendStream.Write(headerbytes, 0, headerbytes.Length);
     }
 }
Beispiel #2
0
        public void AddFile(string s, string name)
        {
            StartMultipartFile(name, s);
#pragma warning disable SCS0018 // Path traversal: injection possible in {1} argument passed to '{0}'
            using (FileStream fs = new FileStream(s, FileMode.Open, FileAccess.Read))
#pragma warning restore SCS0018 // Path traversal: injection possible in {1} argument passed to '{0}'
            {
                byte[] buffer    = new Byte[1024];
                int    bytesRead = fs.Read(buffer, 0, 1024);
                while (bytesRead > 0)
                {
                    SendStream.Write(buffer, 0, bytesRead);
                    bytesRead = fs.Read(buffer, 0, 1024);
                }
            }
        }