Files
Overview of files API methods
post
https://api.codemash.io
/:version/files
Upload File
.NET
Node
PHP
var client = new CodeMashClient(apiKey, projectId);
var filesService = new CodeMashFilesService(client);
​
var directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var filePath = quot;{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"
}
);
}
​
use Codemash\CodemashClient;
use Codemash\CodemashFile;
​
class CodemashService
{
protected CodemashFile $codemashFile;
​
public function __construct()
{
$secretKey = '{YOUR_SECRET_KEY}';
$projectId = '{YOUR_PROJECT_ID}';
​
$client = new CodemashClient($secretKey, $projectId);
$this->codemashFile = new CodemashFile($client);
}
​
public function uploadFile()
{
$responseData = $this->codemashFile->uploadFile([
'path' => 'folder1',
'fileUri' => '{YOUR_FILE_PATH}',
'fileName' => '{YOUR_FILE_NAME}',
]);
}
}
post
https://api.codemash.io
/:version/db/:collectionName/files
Upload Record File
.NET
Node
PHP
var client = new CodeMashClient(apiKey, projectId);
var filesService = new CodeMashFilesService(client);
​
var directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var filePath = quot;{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"
}
);
}
​
use Codemash\CodemashClient;
use Codemash\CodemashFile;
​
class CodemashService
{
protected CodemashFile $codemashFile;
​
public function __construct()
{
$secretKey = '{YOUR_SECRET_KEY}';
$projectId = '{YOUR_PROJECT_ID}';
​
$client = new CodemashClient($secretKey, $projectId);
$this->codemashFile = new CodemashFile($client);
}
​
public function uploadRecordFile()
{
$responseData = $this->codemashFile->uploadRecordFile([
'fileUri' => '{YOUR_FILE_PATH}',
'fileName' => '{YOUR_FILE_NAME}',
'collectionName' => '{COLLECTION_NAME}',
'recordId' => '{RECORD_ID}',
'uniqueFieldName' => 'file_field_name',
]);
}
}
post
https://api.codemash.io
/:version/membership/users/files
Upload User File
.NET
Node
PHP
var client = new CodeMashClient(apiKey, projectId);
var filesService = new CodeMashFilesService(client);
​
var directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var filePath = quot;{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"
}
);
}
​
use Codemash\CodemashClient;
use Codemash\CodemashFile;
​
class CodemashService
{
protected CodemashFile $codemashFile;
​
public function __construct()
{
$secretKey = '{YOUR_SECRET_KEY}';
$projectId = '{YOUR_PROJECT_ID}';
​
$client = new CodemashClient($secretKey, $projectId);
$this->codemashFile = new CodemashFile($client);
}
​
public function uploadUserFile()
{
$responseData = $this->codemashFile->uploadUserFile([
'fileUri' => '{YOUR_FILE_PATH}',
'fileName' => '{YOUR_FILE_NAME}',
'userId' => '{USER_ID}',
'metaFieldName' => 'file_field_name',
]);
}
}
Last modified 2mo ago
Copy link
On this page
post
Upload File
post
Upload Record File
post
Upload User File