Ir para o conteúdo

Exemplo de Script - Baixar Arquivo

Este exemplo demonstra uma ação que baixa um arquivo e salva os dados binários em uma célula.

Esquema de Tabela

Coluna Tipo de dados Chave Primária Gerar automaticamente Anulável
Url NVARCHAR(500) Não Não Não
Size INTEGER Não Não Não
Content BINARY Não Não Não

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;