Files

Overview of files API methods

Upload File

POST https://api.codemash.io/:version/files

Uploads a file.

Path Parameters

NameTypeDescription

version

string

The version of the API endpoint.

Headers

NameTypeDescription

Authorization

string

Your project's secret key.

x-cm-projectid

string

Your project's ID. Can be passed as a query parameter.

Request Body

NameTypeDescription

path

string

Path in your file browser.

{
    Result: ""
}
var client = new CodeMashClient(apiKey, projectId);
var filesService = new CodeMashFilesService(client);

var directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var filePath = $"{directory}\\test.txt";

using (var fsSource = new FileStream(path, FileMode.Open, FileAccess.Read))
{
    var response = await filesService.UploadFileAsync(fsSource, "test.txt", 
        new UploadFileRequest
        {
            Path = "folder1"
        }
    );
}

Upload Record File

POST https://api.codemash.io/:version/db/:collectionName/files

Uploads a file for a record field.

Path Parameters

NameTypeDescription

version

string

The version of the API endpoint.

collectionName

string

Name of a collection.

Headers

NameTypeDescription

Authorization

string

Your project's secret key.

x-cm-projectid

string

Your project's ID. Can be passed as a query parameter.

Request Body

NameTypeDescription

recordId

string

The ID of a record inside collection.

uniqueFieldName

string

Record file field name.

{
    Result: ""
}
var client = new CodeMashClient(apiKey, projectId);
var filesService = new CodeMashFilesService(client);

var directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var filePath = $"{directory}\\test.txt";

using (var fsSource = new FileStream(path, FileMode.Open, FileAccess.Read))
{
    var response = await filesService.UploadRecordFileAsync(fsSource, "test.txt", 
        new UploadRecordFileRequest
        {
            RecordId = "{RECORD_ID}",
            UniqueFieldName = "file_field_name"
        }
    );
}

Upload User File

POST https://api.codemash.io/:version/membership/users/files

Uploads a file for a user meta field.

Path Parameters

NameTypeDescription

version

string

The version of the API endpoint.

Headers

NameTypeDescription

Authorization

string

Your project's secret key.

x-cm-projectid

string

Your project's ID. Can be passed as a query parameter.

Request Body

NameTypeDescription

userId

string

The ID of a user.

metaFieldName

string

User meta-file field name.

{
    Result: ""
}
var client = new CodeMashClient(apiKey, projectId);
var filesService = new CodeMashFilesService(client);

var directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var filePath = $"{directory}\\test.txt";

using (var fsSource = new FileStream(path, FileMode.Open, FileAccess.Read))
{
    var response = await filesService.UploadUserFileAsync(fsSource, "test.txt", 
        new UploadUserFileRequest
        {
            UserId = "{USER_ID}",
            MetaFieldName = "file_field_name"
        }
    );
}

Last updated