CodeMash
  • 🚀Backend as a service
  • 🦄Roadmap
  • 🍕Release Notes
  • Installation
    • Managed Service
    • 🏗️AWS-CDK
    • 🏗️Azure
    • 🏗️Docker
    • 🏗️GC
    • 🏗️Terraform
  • dashboard
    • CodeMash Cloud
    • Project
    • Membership
      • Users
      • Roles
      • Policies
      • Triggers
      • Integrations
        • Apple
        • Azure
        • Facebook
        • Google
        • Twitter
      • Settings
    • Database
      • Collections
        • Schema
          • From Template
          • Structure
        • Tabs
        • Triggers
        • Indexes
        • Shared Forms
      • Taxonomies
        • Terms
        • Schema
        • Settings
      • Aggregation
      • Imports
      • Exports
      • Backups
    • Files
      • Integrations
        • CodeMash
        • S3 Bucket
    • Notifications
      • Push
        • Push Templates
        • Push Templates API
        • Push Notifications
        • Push Notifications API
        • Devices
        • Devices API
        • Integrations
          • Firebase
          • One Signal
          • Expo
      • Email
        • Email Templates
        • Emails
        • Integrations
          • AWS SES
          • Twilio Sendgrid
          • Mailgun
      • 🏗️Server events
      • 🏗️Sms
    • Payments
      • Integrations
        • Apple Pay
        • Google Pay
        • Stripe
        • Kevin.
        • Paysera
        • Decta
    • Scheduler
    • Logs & Monitoring
    • Code
      • Functions
        • Function Inputs
        • Function Templates
          • Node.js
          • Python
          • Ruby
          • Java
          • Go
          • .NET Core
      • CodeMash Functions
        • Google Functions
          • Google Calendar
          • Google Gmail
        • Microsoft Functions
          • Microsoft 365 Users
          • Microsoft 365 Calendar
        • Collection Find
        • Collection Update
        • Users Find
        • Image Resize
        • Html To Pdf
        • Word Document
        • Barcode
        • QR Code
        • Send Email
        • Send Notification
        • Email Reminder
        • Notification Reminder
      • Integrations
        • AWS Lambda
        • Google Cloud Functions
        • Azure Functions
  • Other Topics
    • Apple
      • Developer Portal
      • Bundle Identifier
      • Team ID
      • Service ID
      • Key ID
    • Triggers
    • Tokens Binding
      • Project Tokens
      • Initiator Tokens
      • Receiver Tokens
      • Request Tokens
      • Operation based tokens
      • Template Functions
    • Search parameters
      • Paging
      • Filter
      • Sort
      • Projection
    • data-models
    • Errors
  • SDK
    • Node.js
    • TypeScript
    • .NET
    • 🏗️Go Lang
    • 🏗️Flutter
    • 🏗️Swift
    • 🏗️Kotlin
  • CLI
    • 🏗️CodeMash CLI
  • API
    • Get Started
    • Prerequisites
    • How to test?
    • Cors
    • Project
    • Membership
      • Authentication
      • Users
    • Database
      • Collections
        • Aggregate
        • Change Responsibility
        • Count
        • Delete
        • Delete Many
        • Distinct
        • Find
        • Find One
        • Insert
        • Insert Many
        • References
        • Replace
        • Update
        • Update Many
      • Taxonomies
        • Find
    • Files
    • Code
    • Notifications
      • Push
      • Emails
      • Server Events
      • 🏗️Sms
    • Payments
    • Scheduler
    • Logs & Monitoring
Powered by GitBook
On this page
  • Using SDK
  • Example
  • Working with Files Service

Was this helpful?

Edit on GitHub
  1. dashboard

Files

Store files for your project, optimize for separate screens and automatically bind files with the records from the database

PreviousBackupsNextIntegrations

Last updated 2 years ago

Was this helpful?

CodeMash Files service allows you to store all your project files. These files include files from the database, user files, and custom files. All the files can be seen from the dashboard in the file browser.

To start using Files services and methods you firstly need to enable files service in your CodeMash dashboard.

Features included in files service:

  1. File storage - storing your project files.

Using SDK

If you decide to use one of our provided SDK, the following code shows how to initialize files service.

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

The following are examples of files SDK using different languages and frameworks.

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"
                    }
                );
            }
        }
    }
}
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 = $codemashFile->uploadRecordFile([
            'fileUri' => '{YOUR_FILE_PATH}',
            'fileName' => '{YOUR_FILE_NAME}',
            'collectionName' => '{COLLECTION_NAME}',
            'recordId' => '{RECORD_ID}',
            'uniqueFieldName' => 'file_field_name',
        ]);
    }
}

Working with Files Service

The following links explore the usage of files service:

API