Get a File Stream

Get a metadata and a readable stream of the contents of a File.

πŸ‘

Permissions Required

You must have View permissions to the field this file was uploaded to for this request to succeed

Method Signature

DownloadStream GetFileStream(Guid id);
async Task<DownloadStream> GetFileStreamAsync(Guid id);

Parameters

ParameterTypeDescription
idGuidThe id of the File to get a readable stream of
returnsDownloadStreamThe requested file's metadata and readable stream
DownloadStream GetFileStream(string id);
async Task<DownloadStream> GetFileStreamAsync(string id);
ParameterTypeDescription
idstringThe id of the File to get a readable stream of
returnsDownloadStreamThe requested file's metadata and readable stream

🚧

Stream Disposal

DownloadStream implements IDisposable. Be sure to wrap calls in a using statement, or call Dispose() directly when you are done reading the stream. See the example below.

Example

/*
 * This example demonstrates streaming a File's contents to
 * the Console
 */
using Catalytic.Sdk.Entities;

namespace Catalytic.Sdk.Examples
{
    class Program
    {
        static void Main(string[] args)
        {
            var catalytic = new Catalytic.Sdk.CatalyticClient(Credentials.Default);

            // be sure to wrap the call in a `using` statement so that Dispose() is called on the stream
            using (var file = catalytic.Files.GetFileStream("8d20bdf5-d3bb-4a08-b05b-eb22a8b5c300"))
            {

                Console.WriteLine($"Name: ${file.FileName}");
                Console.WriteLine($"Size (bytes): ${file.Size}");
                Console.WriteLine($"Content-Type: ${file.ContentType}");
                Console.WriteLine("Content:\n----");

                while (!file.Stream.EndOfStream)
                {
                    Console.WriteLine(file.Stream.ReadLine());
                }
            }
        }
    }
}