Skip to end of metadata
Go to start of metadata

This code sample shows how to upload test assets to Sauce Temporary Storage over the REST API using C# and the RestSharp library

using RestSharp;
using RestSharp.Authenticators;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication3
{
    class Program
    {
        // Uploads a file to Sauce Temporary Storage via REST API using the
        // RestSharp library. Be sure to replace the string values for
        // FileName, FilePath, UserName, and AccessKey.

        static void Main(string[] args)
        {
            string FileName = ""; // ex: "NotesList.apk"
            string FilePath = ""; // ex: "C:\\Users\\Sauce11\\Downloads\\NotesList.apk";
            string UserName = ""; // ex: "saucetester"
            string AccessKey = ""; // ex: "123123-abcd-1234-abcd-abc123abc123";

            var client = new RestClient("https://saucelabs.com/rest/v1/");
            client.Authenticator = new HttpBasicAuthenticator(UserName, AccessKey);
            var request = new RestRequest("storage/"+UserName+"/"+FileName+"?overwrite=true", Method.POST);
            request.AddHeader("Content-Type", "application/octet-stream");
            request.AddFile(FileName, FilePath);
            var result = client.Execute(request);
            Console.WriteLine(result.Content);
        }
    }
}

 

If you are running RestSharp under a corporate proxy, you would need to add the following app.config file to your RestSharp project:

app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
	<startup>
		<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> //Our example uses .NET 4.5.2 but it should work for any .NET version
	</startup>
	<system.net>
		<defaultProxy enabled="true" useDefaultCredentials="true">
			<proxy usesystemdefault="true" bypassonlocal="true"/>
		</defaultProxy>
	</system.net>
</configuration>