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

◆ UploadFile() [4/4]

byte[] System.Net.WebClient.UploadFile ( Uri address,
string? method,
string fileName )
inline

Definition at line 757 of file WebClient.cs.

758 {
759 ArgumentNullException.ThrowIfNull(address, "address");
760 ArgumentNullException.ThrowIfNull(fileName, "fileName");
761 if (method == null)
762 {
763 method = MapToDefaultMethod(address);
764 }
765 FileStream fs = null;
766 WebRequest request = null;
768 try
769 {
770 _method = method;
771 byte[] formHeaderBytes = null;
772 byte[] boundaryBytes = null;
773 Uri uri = GetUri(address);
774 bool needsHeaderAndBoundary = uri.Scheme != Uri.UriSchemeFile;
775 OpenFileInternal(needsHeaderAndBoundary, fileName, out fs, out var buffer, ref formHeaderBytes, ref boundaryBytes);
776 request = (_webRequest = GetWebRequest(uri));
777 return UploadBits(request, fs, buffer, 0, formHeaderBytes, boundaryBytes);
778 }
779 catch (Exception ex)
780 {
781 fs?.Close();
782 if (ex is OutOfMemoryException)
783 {
784 throw;
785 }
786 AbortRequest(request);
787 if (ex is WebException || ex is SecurityException)
788 {
789 throw;
790 }
791 throw new WebException(System.SR.net_webclient, ex);
792 }
793 finally
794 {
795 EndOperation();
796 }
797 }
virtual void Close()
Definition Stream.cs:644
byte[] UploadBits(WebRequest request, Stream readStream, byte[] buffer, int chunkSize, byte[] header, byte[] footer)
Uri GetUri(string address)
Definition WebClient.cs:990
virtual WebRequest GetWebRequest(Uri address)
Definition WebClient.cs:428
WebRequest _webRequest
Definition WebClient.cs:76
void OpenFileInternal(bool needsHeaderAndBoundary, string fileName, out FileStream fs, out byte[] buffer, ref byte[] formHeaderBytes, ref byte[] boundaryBytes)
Definition WebClient.cs:691
string MapToDefaultMethod(Uri address)
static void AbortRequest(WebRequest request)
Definition WebClient.cs:929
static string net_webclient
Definition SR.cs:14
Definition SR.cs:7

References System.Net.WebClient._method, System.Net.WebClient._webRequest, System.Net.WebClient.AbortRequest(), System.buffer, System.IO.Stream.Close(), System.Net.WebClient.EndOperation(), System.Net.WebClient.GetUri(), System.Net.WebClient.GetWebRequest(), System.Net.WebClient.MapToDefaultMethod(), System.SR.net_webclient, System.Net.WebClient.OpenFileInternal(), System.Net.WebClient.StartOperation(), System.ArgumentNullException.ThrowIfNull(), System.Net.WebClient.UploadBits(), and System.Uri.UriSchemeFile.