Saving to S3 Storage
Products: FastReport Cloud, FastReport Corporate Server, FastReport Publisher
In this article, we will consider the method of sending a report to S3 storage. Instructions on how to work with tasks are described in the General Information section.
Getting Started
You will need the following tools and capabilities:
Knowledge of using API key in Service solutions.
This article will skip additional information on authentication and authorization.
C# code editor or text editor, such as Visual Studio Code.
Report template.
It can be prepared using the free FastReport Community Designer program.
Active subscription to one of the following products: FastReport Cloud, FastReport Corporate Server, or FastReport Publisher.
Internet access.
Configured and accessible S3 storage.
Note! This guide assumes that you already know how to develop your application in the C# programming language.
Note! The points above describe the recommended tools.
Note! This guide assumes that you have configured S3 storage to accept files from external sources.
Creating a Task
Let's consider creating a template sending task to S3 storage:
// Object initialization
CreateS3UploadTaskVM s3UploadTaskVM = new CreateS3UploadTaskVM
{
Name = "S3 Sending Task",
InputFile = new InputFileVM
{
EntityId = "{template identifier}",
Type = FileKind.Template
},
AccessKey = "{public_access_key}",
SecretKey = "{secret_access_key}",
Url = "https://example.com",
BucketName = "{bucket_name}",
UseAws = true,
EnableSsl = true,
Region = "us-east-1",
DestinationFolder = "{/path_to_folder/}",
SubscriptionId = "{workspace identifier}"
};
// Creating a task
TaskBaseVM s3UploadTask = await tasksClient.CreateTaskAsync(s3UploadTaskVM);
// Run task by identifier
await tasksClient.RunTaskByIdAsync(s3UploadTask.Id);
Real object identifiers should be entered in the EntityId and SubscriptionId fields. Otherwise, the task will be aborted with an error.
Executing Task from Request Body
// Run task from request body
await tasksClient.RunTaskAsync(new RunS3UploadTaskVM
{
InputFile = new RunInputFileVM
{
EntityId = "{template identifier}",
Type = FileKind.Template
},
AccessKey = "{public_access_key}",
SecretKey = "{secret_access_key}",
Url = "https://example.com",
BucketName = "{bucket_name}",
UseAws = true,
EnableSsl = true,
Region = "us-east-1",
DestinationFolder = "{/path_to_folder/}",
SubscriptionId = "{workspace identifier}"
});
Note! In this case, the S3 sending will be performed directly by this request and the task will not be saved in the database.
Updating Task by Identifier
await tasksClient.UpdateTaskAsync("{task identifier}", new UpdateS3UploadTaskVM()
{
InputFile = new RunInputFileVM
{
EntityId = "{updated template identifier}",
Type = FileKind.Template
},
AccessKey = "{Updated public_access_key}",
SecretKey = "{Updated secret_access_key}",
Url = "Updated S3 storage address",
BucketName = "{Updated bucket_name}",
UseAws = true,
EnableSsl = true,
Region = "{Updated region}",
DestinationFolder = "{/Updated_path_to_folder/}"
});