Description
The UploadFile
method is a static extension method provided by the SandboxToolExtensions
class. It is used to upload a file to a specified package in the Sandbox environment. This method is asynchronous and returns a Task<bool>
indicating the success or failure of the upload operation.
Usage
To use the UploadFile
method, you need to provide the following parameters:
package
: The Package
object representing the target package where the file will be uploaded.
absolutePath
: A string
representing the absolute path of the file to be uploaded.
relativePath
: A string
representing the relative path within the package where the file should be stored.
progress
: A DataProgress.Callback
delegate to report the progress of the upload operation.
token
: A CancellationToken
to observe while waiting for the task to complete, allowing the operation to be cancelled.
Ensure that the file paths are correct and that the package is properly initialized before calling this method.
Example
// Example usage of UploadFile method
// Assume 'package' is a valid Sandbox.Package object
// 'absolutePath' is the full path to the file on disk
// 'relativePath' is the path within the package
// 'progress' is a callback to report progress
// 'cancellationToken' is used to cancel the operation if needed
var success = await SandboxToolExtensions.UploadFile(
package,
"/path/to/local/file.txt",
"assets/file.txt",
progress => Console.WriteLine($"Progress: {progress}%"),
cancellationToken
);
if (success)
{
Console.WriteLine("File uploaded successfully.");
}
else
{
Console.WriteLine("File upload failed.");
}