Skip to Content

Scripting Example - Download File

This example demonstrates an action which downloads a file and saves the binary data to a cell.

Table Schema

Column Data Type Primary Key Auto-generate Nullable
Url NVARCHAR(500) No No No
Size INTEGER No No No
Content BINARY No No No

Script

using System.IO;
using System.Net.Http;

var url = Row["Url"].GetValueAsString();

var client = new HttpClient();

byte[] bytes;

using (HttpResponseMessage response = await client.GetAsync(url))
{
    if (!response.IsSuccessStatusCode)
    {
        const string message = "Failed to download file.";
        throw new InvalidOperationException(message);
    }

    bytes = await response.Content.ReadAsByteArrayAsync();
}

Row["Size"].Value = bytes.Length;
Row["Content"].Value = bytes;