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
Parameter | Type | Description |
---|---|---|
id | Guid | The id of the File to get a readable stream of |
returns | DownloadStream | The requested file's metadata and readable stream |
DownloadStream GetFileStream(string id);
async Task<DownloadStream> GetFileStreamAsync(string id);
Parameter | Type | Description |
---|---|---|
id | string | The id of the File to get a readable stream of |
returns | DownloadStream | The requested file's metadata and readable stream |
Stream Disposal
DownloadStream
implementsIDisposable
. Be sure to wrap calls in ausing
statement, or callDispose()
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());
}
}
}
}
}
Updated over 2 years ago