'Winform file uploader not uploading large files

So im working on a .raw file uploader made in C# winform, and its working fine but any files a little bit above 2GB don't upload to the server. Im using the RestSharp library, heres the upload function

private void uploadfile(string filelocation)
        {
            
            output.AppendText(Environment.NewLine + DateTime.Now + $" Start Uploading {filelocation}");
            string newfilelocation;
            if (nocopy.Checked) {
                newfilelocation = filelocation;

            }
            else
            {

                newfilelocation = Path.GetDirectoryName(filelocation) + @"\temp\" + Path.GetFileName(filelocation);

                //check if a temp patch exits, create one if not.
                string temppath = Path.GetDirectoryName(filelocation) + @"\temp\";

                bool exists = System.IO.Directory.Exists(temppath);

                if (!exists)
                    System.IO.Directory.CreateDirectory(temppath);

                if (File.Exists(newfilelocation))
                {
                    File.Delete(newfilelocation);
                }

                try //for somereason, copy file fails sometimes...
                {
                    File.Copy(filelocation, newfilelocation, true);

                }

                catch
                {
                    output.AppendText(Environment.NewLine + DateTime.Now + $" {newfilelocation} uploading failed once will try again");

                    System.Threading.Thread.Sleep(30000);


                    try //2nd try
                    {
                        File.Copy(filelocation, newfilelocation, true);

                    }

                    catch
                    {
                        output.AppendText(Environment.NewLine + DateTime.Now + $" {newfilelocation} uploading failed second time");

                        return;
                    }
                    // Todo: Additional recovery here,
                    // like telling the calling code to re-open the file selection dialog
                }

            }

            var client = new RestClient(txtserver.Text);
            client.Timeout = 30 * 60 * 1000;// 1000 ms = 1s, 30 min = 30*60*1000

            client.Authenticator = new HttpBasicAuthenticator(txtusername.Text, txtpassword.Text);

            if (!File.Exists(newfilelocation))
            {
                MessageBox.Show("Please check file location");
                return;
            }

            var request = new RestRequest();

            request.Method = Method.POST;
            request.AddHeader("Accept", "application/json");
            request.Parameters.Clear();
            request.AddHeader("Content-Type", "multipart/form-data");
            if(String.IsNullOrEmpty(txtsamplename.Text))
            {
                request.AddParameter("run_name", Path.GetFileNameWithoutExtension(newfilelocation));
            }
            else
            {
                request.AddParameter("run_name", txtsamplename.Text);

            }

            request.AddParameter("project_name", txtprojectname.Text);
            request.AddParameter("run_desc", txtdescription.Text);
            request.AddParameter("qc_tool", qctool.SelectedIndex);
            request.AddParameter("temp_data", TempData.Checked);
            request.AddFile("rawfile", newfilelocation);
            request.ReadWriteTimeout = 2147483647;
            request.Timeout = 2147483647;
            var response = client.Execute(request);
            output.AppendText(Environment.NewLine + response.Content);
            output.AppendText(Environment.NewLine + DateTime.Now + $" {newfilelocation} uploaded");
            if (!nocopy.Checked)
            {
                File.Delete(newfilelocation);
            }
        }

Wondering what solutions there could be so i can upload larger files. The server isnt the issue, since the files can be uploaded to the server using a browser extension. Its on the winform app side.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source