Skip to main content

File Management

InCountry Web Services Proxy doesn't fully support files within your requests, it simply proxies them as-is without saving the files to InCountry DRaaS.

If you would like to store files on InCountry DRaaS, you have to use the file management endpoints available in REST API.

Overview

InCountry DRaaS allows you to:

note

During uploading of files to InCountry DRaaS, you need to associate them with specific records already stored on InCountry DRaaS. Attachments cannot be imported without a record attribution.

You have to create or import records, which attachments can be further associated with. That’s why we call files – attachments. You can add multiple attachments to one record.

The example of the file upload will be as follows:

Code example
var myHeaders = new Headers();
myHeaders.append("Content-Type", "multipart/form-data");
myHeaders.append("x-filename", "customfilename.txt");
myHeaders.append("Authorization", "Bearer <token>");

var formdata = new FormData();
formdata.append("file", fileInput.files[0], "file.txt");

var requestOptions = {
method: 'POST',
headers: myHeaders,
body: formdata,
redirect: 'follow'
};

fetch(
"https://cn-restapi-mt-01.incountry.io/webapi/records/<record_key>/files",
requestOptions
);
note

Please note that this is an attachment request, which means that a record with the <record_key> field must exist before the files can be attached.

To download the attachment, you can perform the following request:

Code example
var myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer <token>");

var requestOptions = {
method: 'GET',
headers: myHeaders,
redirect: 'follow'
};

fetch(
"https://cn-restapi-mt-01.incountry.io/webapi​/records/<record_key>/files/<file_id>",
requestOptions
);
note

Attachment-based access policy is not supported. We do not regulate access to specific attachments of the record for each user, considering user-specific permissions. But we support the record-based access policy. You can split your attachments by records.

Attachments API

It is possible to attach files to records in InCountry Vault. Please note, that files should always have a parent record. Deleting a record will result in the deletion of all the files attached to it.

Available Attachment Fields

FieldTypeSpecifics
file_idstringUnique identifier of an attachment.
filenamestringName of an attachment.
hashstringHash of an attachment.
mime_typestringMIME type of an attachment.
sizestringSize of an attachment in bytes.
created_atstring(date-time)Timestamp when an attachment was uploaded to the InCountry Vault.
updated_atstring(date-time)Timestamp when an attachment was updated in the InCountry Vault.
download_linkstringLink to download an attachment from the InCountry Vault.

Uploading Attachments

POST /api/models/{schemaName}/{country}/{record_key}/files

Request parameters

All the request parameters are required.

ParametersTypeValueDescription
countrystring (ISO country code (lowercase))sgCountry which a new attachment is uploaded to.
record_keystringatt1234A key of the record which the attachment is associated with.
filestring(binary)A name of the attachment for upload.

The request body should be a binary string of the file you are uploading.

cURL request
curl --request POST \
--url 'https://{restApiURLAddress}/api/models/{schemaName}/{country}/{record_key}/files' \
--header 'Authorization: Bearer {ACCESS_TOKEN}' \
--header 'Content-Type: multipart/form-data; boundary=---011000010111000001101001' \
--header 'x-filename: file_name.{extension}'
--form 'file=@"{file local path}"'

//URL EXAMPLE
https://se-restapi-mt-01.incountry.io/api/users/se/d1c2e12cfeababc8b95daf6902e210b1/files

//LOCAL PATH TO FILE EXAMPLE
--form 'file=@"/Users/John/Projects/files/index.html"'

Responses

STATUS 201 - JSON The attachment has been successfully uploaded.

Example
{
"file_id": "5416a334-6ce6-4e3b-9a0d-464cb417c094",
"filename": "index.html",
"hash": "78701b482fc9738e26f32254bbe7d71990f5025a9b728046a280a3822cdf5cad",
"mime_type": "application/x-sh",
"size": 279,
"created_at": "2021-03-26T11:36:44.000Z",
"updated_at": "2021-03-26T11:36:44.000Z",
"download_link": "https://se-mt-01.incountry.io/v2/storage/records/se/310459560d9e757d6e51be45a5aad862fbb81c52d72a026e75d21366ac223a40/attachments/5416a334-6ce6-4e3b-9a0d-464cb417c094"
}

STATUS 400 - An invalid file has been provided.

STATUS 401 - Access is denied.

STATUS 403 - File storage is not available.

STATUS 404 - The target record has not been found.

STATUS 409 - File storage for the country is not available.

STATUS 413 - The request payload exceeds the maximal size.

STATUS 415 - An unsupported request content type.

STATUS 422 - Validation of input parameters has failed.

STATUS 429 - The number of allowed requests has been exceeded.

STATUS 5** - Server error.

Downloading Attachments

GET /api/models/{schemaName}/{country}/{record_key}/files/{file_id}

Request parameters

All the request parameters are required.

ParametersTypeValueDescription
countrystring (ISO country code (lowercase))sgCountry where the attachment is stored.
record_keystringatt1234A record key of the record which the attachment is associated with.
file_idstring (binary)The file identifier of the attachment stored on the InCountry platform.
cURL request
curl --request GET \
--url 'https://{restApiURLAddress}/api/models/{schemaName}/{country}/{record_key}/files/{file_id}' \
--header 'Authorization: Bearer {ACCESS_TOKEN}' \

//URL EXAMPLE
https://se-restapi-mt-01.incountry.io/api/users/se/d1c2e12cfeababc8b95daf6902e210b1/files/d4f0a504-82a6-40b7-b153-1ec81d2f5ae0

Responses

STATUS 200 - application/octet-stream The file has been passed for download

STATUS 401 - Access is denied.

STATUS 403 - File storage is not available or insufficient permissions.

STATUS 404 - The target record or file has not been found.

STATUS 422 - Validation of input parameters has failed.

STATUS 429 - The number of allowed requests has been exceeded.

STATUS 5** - Server error.

Moving Attachments between Records

POST /api/models/{schemaName}/{source_record_key}/files/move/{destination_record_key}

Request parameters

All the request parameters are required.

ParametersTypeValueDescription
source_record_keystringd1c2e12cfeababc8b95daf6902e210b1Key of the record from which the attachment is moved.
destination_record_keystringd1c2e12cfd454ababc8b95daf6902e210b1Key of the record to which the attachment is moved.

Request body

Within the request body, you need to specify the list of attachment identifiers for moving between the specified source and destination records.

{
"attachment_ids": [
"string"
]
}
cURL request
curl --request POST \
--url '/api/models/{schemaName}/{source_record_key}/files/move/{destination_record_key}' \
--header 'Authorization: Bearer {ACCESS_TOKEN}' \
--data '{
"attachment_ids": [
"string"
]
}

Responses

STATUS 204 - Attachments have been successfully moved.

STATUS 401 - One of the attachment identifiers is not accessible.

STATUS 401 - Access is denied.

STATUS 403 - File storage is not available.

STATUS 404 - One of the records has not been found.

STATUS 422 - Validation of input parameters has failed.

STATUS 429 - The number of allowed requests has been exceeded.

STATUS 5** - Server error.

Deleting Attachments

DELETE /api/models/{schemaName}/{country}/{record_key}/files/{file_id}

Request parameters

All the request parameters are required.

ParametersTypeValueDescription
countrystring (ISO country code (lowercase))sgCountry where the attachment is stored.
keystringatt1234A record key of the attachment.
file_idstringThe file identifier of the attachment stored in InCountry Vault.
cURL request
curl --request DELETE \
--url 'https://{restApiURLAddress}/api/models/{schemaName}/{country}/{record_key}/files/{file_id}' \
--header 'Authorization: Bearer {ACCESS_TOKEN}' \

Responses

STATUS 204 - The attachment has been successfully deleted.

STATUS 401 - Access is denied.

STATUS 403 - File storage is not available.

STATUS 404 - The target record or file has not been found.

STATUS 422 - Validation of input parameters has failed.

STATUS 429 - The number of allowed requests has been exceeded.

STATUS 5** - Server error.