Files
Store files for your project, optimize for separate screens and automatically bind files with the records from the database
Using SDK
var projectId = Guid.Parse("{YOUR_PROJECT_ID}");
var apiKey = "{YOUR_SECRET_KEY}";
var client = new CodeMashClient(apiKey, projectId);
var filesService = new CodeMashFilesService(client);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);
}
}Example
using System;
using CodeMash.Client;
using CodeMash.Membership.Services;
using Isidos.CodeMash.ServiceContracts;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
// 1. Get your Project ID and Secret Key
var projectId = Guid.Parse("{YOUR_PROJECT_ID}");
var apiKey = "{YOUR_SECRET_KEY}";
// 2. Create a general client for API calls
var client = new CodeMashClient(apiKey, projectId);
// 3. Create a service object
var filesService = new CodeMashFilesService(client);
// 4. Get path to your file
var directory = Path.GetDirectoryName(
Assembly.GetExecutingAssembly().Location
);
var filePath = $"{directory}\\test.txt";
// 5. Get file stream
using (var fsSource = new FileStream(path, FileMode.Open,
FileAccess.Read))
{
// 6. Call an API method
var response = await filesService.UploadFileAsync(
fsSource,
"test.txt",
new UploadFileRequest
{
Path = "folder1"
}
);
}
}
}
}Working with Files Service
Last updated