File Field Manager service
The File Field Manager service includes endpoints for uploading and downloading files linked to file fields. As a sample use case, you might leverage this service to create a custom page with links for downloading files from Relativity.
The Relativity Services API also provides functionality for downloading and uploading files linked to file fields. It also supports the use of progress indicators and cancellation tokens through .NET. For more information, see File Field Manager API.
This page contains the following information:
- Sample workflow for working with file fields
- Submit calls as multipart/form-data
- Uploading files to file fields
- Downloading files from file fields
Sample workflow for working with file fields
- 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.
- 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.
- Save the updated RDO. Use the Object Manager API to update RDO. See Update fields on a Document object or RDO.
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.
Submit calls as multipart/form-data
When you submit a call to the File Field Manager service, it uses an IKeplerStream as input, which requires the content type to be set as multipart/form-data.
If you use the C# proxy to call the service, the proxy automatically handles this process. However, if you are calling the service via REST, submit the call as follows:
- The first part of the form is the JSON payload that has all of the data for the API in addition to the IKeplerStream.
- The second part of the form is the binary data for the IKeplerStream.
The following code sample illustrates how you can make this call:
var file = $('#uploadFile').get(0).files[0]; var jsonData = {}; var blob = new Blob([JSON.stringify(jsonData, null, 2)], { type: 'application/json' }); file.type = 'application/octet-stream'; var formData = new FormData(); formData.append('json', blob); formData.append('stream', file); $.ajax({ headers: { 'X-CSRF-Header': '-' }, url: "/Path/To/Service", // Change this to the path to your service type: "POST", data: formData, processData: false, contentType: false, forceSync: false, cache: false });
Uploading files to file fields
To upload a file to a file field, use a URL with following general format:
<host>/Relativity.Rest/API/Relativity.FileField/workspace/{workspaceId}/file/upload
Note: Set the {workspaceId} to -1 to indicate the admin-level context.
The following URL contains sample data:
<host>/Relativity.Rest/API/Relativity.FileField/workspace/1016847/file/upload
The request must include the following fields:
- field - a reference to the field that you want associated with the uploaded file. It contains this field:
- ArtifactID - the Artifact ID of the field.
- objectRef - a reference to the object that will contain the uploaded file. It contains this field:
- ArtifactID - the Artifact ID of the object.
- fileName - the name of the file that you want to upload. Set this field to only the file name. Don't include the path to the file. See Submit calls as multipart/form-data.
The request content is a bit stream representing the file that you are uploading. See the following sample JSON:
{ "field":{ "ArtifactID":1098145 }, "objectRef":{ "ArtifactID":1001637 }, "fileName":"Sample File" },
The response contains the following fields:
- UploadedFileGuid - the GUID used to identify the uploaded file in temporary storage.
- Filename - the name of the file that you uploaded.
{ "UploadedFileGuid":"8bb7059c-07cc-453a-8b84-981296d7263d", "Filename":"Sample File" }
Downloading files from file fields
To download a file from a file field, use a URL with following general format:
<host>/Relativity.Rest/API/Relativity.FileField/workspace/{workspaceId}/file/download
Note: Set the {workspaceId} to -1 to indicate the admin-level context.
The following URL contains sample data:
<host>/Relativity.Rest/API/Relativity.FileField/workspace/1016847/file/download
The request must include the following fields:
- field - a reference to the field containing the file that you want to download. It contains this field:
- ArtifactID - the Artifact ID of the field.
- objectRef - a reference to the object containing the file that you want to download. It contains this field:
- ArtifactID - the Artifact ID of the object.
{ "field":{ "ArtifactID":1035345 }, "objectRef":{ "ArtifactID":1037898 } }
The response is a bit stream representing the file that you are downloading.