Add a Temporary File

Creates a temporary file in a specified location in Librarian.

Librarian supports the creation of temporary files. These temporary files do not have to be associated with the $temp space; they can exist anywhere in the Main space as well.

The purpose of this API is to reduce the number of calls that are needed to create a temporary file. Without this API, you must first verify that the name of the proposed temporary file is unique and then create the actual temporary file. By using the Add a Temporary File endpoints, you can create an empty temporary file with a single call.

Note: For more information about this command, including descriptions of any path and request parameters, request body schema, response codes and schemas, and payload examples, refer to the online API reference for this command at the following web page:

Add a temporary file

URI

https://bartendercloud.com/api/librarian/spaces/{spaceId}/files/tempfile

Note: The bartendercloud.com domain that is referenced in the URI and in the code example that follows must be replaced with the contents of the DataCenterURI claim that is extracted from your access token. For more information, refer to Extracting the DataCenterURI Claim.

Path Parameters

spaceId

Type: Integer <int32>

Specifies the ID of the requested space. Use the number 1 to target the Main space or the number 2 to target the $temp space. Required.

Query Parameters

None.

Example

Request body: See TempFileAddRequest.

Response: See FileChange.

Copy
// Assume that the int variable spaceId=1 (this references the Main space and is substituted into the URI below).
// Assume that folderId is the ID of the folder that will contain the new temporary file.
var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {accessToken}");

var addTempFileRequest = new TempFileAddRequest() {
    FolderId = folderId,     // The folder that will contain the temporary file.
    Comment = "Creating a new temporary file",
    FileContentType = "txt",
    Encryption = "",    // Not encrypted.
    InheritFromFolderPermissions = true,
    Metadata = null,
    Permissions = null,    // Permissions are inherited from the containing folder.
    IsHidden = false,
    Prefix = "Tmp"        // The generated file name will have a 'Tmp' prefix.
    Extension = "txt"     // The generated file name will have a '.txt' file name extension.
};

HttpRequestMessage request = new HttpRequestMessage
{
   RequestUri = new Uri($"https://bartendercloud.com/api/librarian/spaces/{spaceId}/files/tempfile"),
   Content = new StringContent(JsonConvert.SerializeObject(addTempFileRequest), Encoding.UTF8, "application/json"),
   Method = HttpMethod.Post
};

HttpResponseMessage msg = await client.SendAsync(request);

if (msg.IsSuccessStatusCode)
{
   return JsonConvert.DeserializeObject<FileChange>(await msg.Content.ReadAsStringAsync());
}