static Task<bool> PutAsync( System.IO.Stream fileStream, string endpoint, Sandbox.Utility.DataProgress/Callback progress, CancellationToken token )

robot_2Generated
code_blocksInput

Description

The PutAsync method is a static method of the Editor.EditorUtility class. It is used to asynchronously upload data from a stream to a specified endpoint. This method supports progress reporting and cancellation.

Usage

To use the PutAsync method, you need to provide a Stream object containing the data to be uploaded, a string representing the endpoint URL, a progress callback to monitor the upload progress, and a cancellation token to handle task cancellation.

Example

// Example usage of PutAsync
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;

public class Example
{
    public async Task UploadFileAsync(string filePath, string endpoint)
    {
        using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
        {
            CancellationTokenSource cts = new CancellationTokenSource();
            Sandbox.Utility.DataProgress.Callback progressCallback = (progress) =>
            {
                Console.WriteLine($"Upload progress: {progress * 100}%");
            };

            bool success = await Editor.EditorUtility.PutAsync(fileStream, endpoint, progressCallback, cts.Token);

            if (success)
            {
                Console.WriteLine("File uploaded successfully.");
            }
            else
            {
                Console.WriteLine("File upload failed.");
            }
        }
    }
}