File Field Manager API

The File Field Manager API exposes a service for uploading and downloading files linked to file fields. For uploads, the overloaded UploadAsync() method supports the use of progress indicators and cancellation tokens. As a sample use case, you might leverage this service to create a custom page with links for downloading files from Relativity.

You can also use File Field Manager service through REST. However, this service doesn't support cancellation tokens or progress indicators through REST. For more information, see File Field Manager service.

This page contains the following information:

File Field Manager API fundamentals

The Relativity.Services.FileField namespace contains the IFileFieldManager interface, which exposes the following methods:

Sample workflow for working with file fields

The sample workflow outlines how you might use the Object Manager API in conjunction to the File Field Manager API to add files to Relativity:

  1. Create a Relativity object with field of type File. For example, you could use the Object Manager API to create an RDO with a File field. See Create an RDO and its specified fields.
  2. Upload a file as the value for the File field created in step 1. Use the File Field Manager API to upload this file. See Uploading files to file fields.
  3. Save the updated RDO. Use the Object Manager API to update RDO. See Object Manager API.

After you upload a file to Relativity via the File Field Manager API, it is added to temporary storage on the server until the RDO with the File field is saved. If the RDO with the File field and associated file aren’t saved, the server deletes it after about twenty-four hours.

Downloading files from file fields

To download a file from a file field, pass the following arguments to the DownloadAsync() method:

The DownloadAsync() method returns the content of the file as a stream.

public async Task<bool> DownloadAsync(IHelper helper)
{
    var objectArtifactId = this.SampleRDO_ID;
    var fieldArtifactId = this.SampleField_File_ID;
    var workspaceID = this.SampleWorkspace_ID;
    var relativityObject = new RelativityObjectRef
    {
        ArtifactID = objectArtifactId
    };
    var field = new FieldRef() { ArtifactID = fieldArtifactId };

    bool success = false;

    using (IFileFieldManager proxy = helper.GetServicesManager().CreateProxy<IFileFieldManager>(ExecutionIdentity.User))
    {
        Logging.ISampleLogger logger = _logger.ForContext("MethodName", nameof(DownloadAsync), false);

        try
        {
            IKeplerStream stream = await proxy.DownloadAsync(workspaceID, relativityObject, field);
            Stream file = stream.GetStreamAsync().Result;

            success = stream.GetStreamAsync().Status == TaskStatus.RanToCompletion;
        }
        catch (Exception ex)
        {
            logger.LogError(ex, "Unhandled Exception");
        }
    }

    return success;
}

Uploading files to file fields

To upload a file to a file field, pass the following arguments to the UploadAsync() method:

The UploadAsync() method returns a FieldRef object.

public async Task<bool> UploadAsync(IHelper helper)
{
    var success = false;

    var objectArtifactId = this.SampleRDO_ID;
    var fieldArtifactId = this.SampleField_File_ID;
    var workspaceID = this.SampleWorkspace_ID;
    var fileName = "LoremIpsum.docx";
    var relativityObject = new RelativityObjectRef
    {
        ArtifactID = objectArtifactId
    };
    var field = new FieldRef() { ArtifactID = fieldArtifactId, Name = fileName };
    var filePath = string.Format("{0}\\SampleFiles\\{1}", Directory.GetCurrentDirectory(), fileName);

    using (IFileFieldManager proxy = helper.GetServicesManager().CreateProxy<IFileFieldManager>(ExecutionIdentity.User))
    {
        Logging.ISampleLogger logger = _logger.ForContext("MethodName", nameof(DownloadAsync), false);

        try
        {
            var keplerStream = new KeplerStream(File.OpenRead(filePath));
            var uploadedFile = await proxy.UploadAsync(workspaceID, field, relativityObject, fileName, keplerStream);

            success = uploadedFile?.UploadedFileGuid != null;
        }
        catch (Exception ex)
        {
            logger.LogError(ex, "Unhandled Exception");
        }
    }

    return success;
}

Community Updates

Aero Developer FAQ Evolving the Platform Most recent release notes
Learn more Learn more Learn more

Additional Resources

   
Access Third-Party Tools with GitHub     Create .NET Apps Faster with NuGet
Visit github     visit nuget