Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ OpenFileInternal()

void System.Net.WebClient.OpenFileInternal ( bool needsHeaderAndBoundary,
string fileName,
out FileStream fs,
out byte[] buffer,
ref byte[] formHeaderBytes,
ref byte[] boundaryBytes )
inlineprivate

Definition at line 691 of file WebClient.cs.

692 {
693 fileName = Path.GetFullPath(fileName);
694 WebHeaderCollection headers = Headers;
695 string text = headers["Content-Type"];
696 if (text == null)
697 {
698 text = "application/octet-stream";
699 }
700 else if (text.StartsWith("multipart/", StringComparison.OrdinalIgnoreCase))
701 {
702 throw new WebException(System.SR.net_webclient_Multipart);
703 }
704 fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
705 int num = 8192;
706 _contentLength = -1L;
707 if (string.Equals(_method, "POST", StringComparison.Ordinal))
708 {
709 if (needsHeaderAndBoundary)
710 {
711 string text2 = $"---------------------{DateTime.Now.Ticks:x}";
712 headers["Content-Type"] = "multipart/form-data; boundary=" + text2;
713 string s = "--" + text2 + "\r\nContent-Disposition: form-data; name=\"file\"; filename=\"" + Path.GetFileName(fileName) + "\"\r\nContent-Type: " + text + "\r\n\r\n";
714 formHeaderBytes = System.Text.Encoding.UTF8.GetBytes(s);
715 boundaryBytes = System.Text.Encoding.ASCII.GetBytes("\r\n--" + text2 + "--\r\n");
716 }
717 else
718 {
719 formHeaderBytes = Array.Empty<byte>();
720 boundaryBytes = Array.Empty<byte>();
721 }
722 if (fs.CanSeek)
723 {
724 _contentLength = fs.Length + formHeaderBytes.Length + boundaryBytes.Length;
725 num = (int)Math.Min(8192L, fs.Length);
726 }
727 }
728 else
729 {
730 headers["Content-Type"] = text;
731 formHeaderBytes = null;
732 boundaryBytes = null;
733 if (fs.CanSeek)
734 {
735 _contentLength = fs.Length;
736 num = (int)Math.Min(8192L, fs.Length);
737 }
738 }
739 buffer = new byte[num];
740 }
static ? string GetFileName(string? path)
Definition Path.cs:200
static string GetFullPath(string path)
Definition Path.cs:881
WebHeaderCollection Headers
Definition WebClient.cs:197
static string net_webclient_Multipart
Definition SR.cs:18
Definition SR.cs:7
static Encoding UTF8
Definition Encoding.cs:526
static Encoding ASCII
Definition Encoding.cs:511

References System.Net.WebClient._contentLength, System.Net.WebClient._method, System.Text.Encoding.ASCII, System.buffer, System.Net.Equals, System.IO.Path.GetFileName(), System.IO.Path.GetFullPath(), System.Net.WebClient.Headers, System.L, System.Math.Min(), System.SR.net_webclient_Multipart, System.s, System.text, and System.Text.Encoding.UTF8.

Referenced by System.Net.WebClient.UploadFile(), and System.Net.WebClient.UploadFileAsync().