Dataswyft API Platform: Developers Docs
WebsiteGitHubSlackLogin
  • About Dataswyft
    • Community & Support
  • Learn about Dataswyft Platform
    • Decentralized Data Servers
    • Personal Data Account
      • HMIC Permissions
      • Namespaces
      • Single Sign-On
    • Data Wallet
      • Data Wallet Canvas and Solutions
      • CheckD Data Wallet: Release Notes
    • Dataswyft One
      • Compute Tools
  • Build on Dataswyft Platform
    • Dataswyft One APIs
      • Data API
        • Filtering, Querying & Transforming Data
        • Data Debit
      • File Storage API
      • Computations API
      • Postman Collection
    • Integrating with Data Wallets
    • Getting Started
      • Quick Start
      • Developers Portal
        • Updating and Submitting an Application
        • Deleting an Application
        • Application Statuses
      • Application Example - React
        • 1. Environment Setup
        • 2. Create Main Structure
        • 3. Main Page & Routing
        • 4. User Authentication
        • 6. CRUD Operations
        • 5. Component Pages
  • Deploy
    • Application Review
    • Rating Assurance & Certification
    • Live Application Ratings
  • Knowledge Base
    • Security Practices
    • FAQ
    • Glossary of Terms
  • Dataswyft
Powered by GitBook
On this page

Was this helpful?

  1. Build on Dataswyft Platform
  2. Advanced Topics
  3. User Journeys
  4. Password Management
  5. Guides
  6. JavaScript

4. File Storage

File API

Upload a File

Parameters

Type

metadata

FileMetadataReq

file

ArrayBuffer | Buffer

fileType

string

Response:

  • FileMetadataRes: The File metadata.

FileMetadataReq type:

interface FileMetadataReq {
  name: string;
  source: string;
  tags?: string[];
  title?: string;
  description?: string;
  dateCreated?: number;
  lastUpdated?: number;
}

Response type:

interface FileMetadataRes {
  fileId: string;
  name: string;
  source: string;
  tags?: string[];
  title?: string;
  description?: string;
  dateCreated: number;
  lastUpdated: number;
  status: FileStatus;
  contentUrl?: string;
  contentPublic: boolean;
  permissions: FilePermissions;
}

interface FileStatus {
  status: string;
  size?: number;
}

interface FilePermissions {
  userId: string;
  contentReadable: boolean;
}

Example:

try {
    const meta = {
                "name": "testFileName",
                "source": "applicationName",
                "tags": [
                    "iphone",
                    "photo",
                ]
            };
    const file = []; // ArrayBuffer or Buffer

    const result = await hat.files().uploadFile(meta, file, "image/png");

    if (result.parsedBody) {
        // result.parsedBody contains the File metadata.
    }
} catch (error) {
  // Failed to upload a file...
}

Example response:

{
  "fileId": "applicationnametestfilename-5",
  "name": "testFileName",
  "source": "applicationName",
  "dateCreated": "2020-03-04T13:13:37.041Z",
  "lastUpdated": "2020-03-04T13:13:37.042Z",
  "tags": [
    "iphone",
    "photo"
  ],
  "status": {
    "status": "New"
  },
  "contentUrl": "https://hubat-net-hatservice-v3ztbxc9civz-storages3bucket-m0gs7co0oyi2.s3.eu-west-1.amazonaws.com/testing.hubat.net/applicationnametestfilename-5?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20190404T131337Z&X-Amz-SignedHeaders=host%3Bx-amz-server-side-encryption&X-Amz-Expires=299&X-Amz-Credential=AKIAICFRCZUZIP4PQ64A%2F20190404%2Feu-west-1%2Fs3%2Faws4_request&X-Amz-Signature=6e7b112fca980dafe9935e8c849dfdb7e4e49abb658947909ec35c12370247b2",
  "contentPublic": false,
  "permissions": [
    {
      "userId": "de35e18d-147f-4664-8de7-409abf881754",
      "contentReadable": true
    }
  ]
}

Mark a file as public

Parameters

Type

fileId

string

Response:

  • FileMetadataRes: The File metadata.

Example:

try {
    const result = await hat.files().markFileAsPublic("file-id");

    if (result.parsedBody) {
        // result.parsedBody contains the File metadata.
    }
} catch (error) {
  // Failed to mark a file as public...
}

Mark a file as private

Parameters

Type

fileId

string

Response:

  • FileMetadataRes: The File metadata.

Example:

try {
    const result = await hat.files().markFileAsPrivate("file-id");

    if (result.parsedBody) {
        // result.parsedBody contains the File metadata.
    }
} catch (error) {
  // Failed to mark a file as private...
}

Update File metadata

Parameters

Type

fileId

string

Response:

  • FileMetadataRes: The File metadata.

Example:

try {
    const meta = {
                "name": "differentFileName",
                "source": "applicationName",
                "tags": [
                    "iphone",
                    "photo",
                    "extra tag"
                ]
            };
    const result = await hat.files().updateFileParameters("file-id", meta);

    if (result.parsedBody) {
        // result.parsedBody contains the File metadata.
    }
} catch (error) {
  // Failed to update file's metadata...
}

Search Files

Parameters

Type

metadata

FileMetadataReq

Response:

  • Array: An array of File metadata.

Example:

try {
    const meta = {
                "name": "",
                "source": "applicationName",
                "tags": [
                    "iphone",
                    "photo",
                ]
            };
    const result = await hat.files().searchFiles(meta);

    if (result.parsedBody) {
        // result.parsedBody contains an array of File metadata.
        // The result contains all the files with the tags "iphone" and "photo" with the same source.
    }
} catch (error) {
  // Failed to search for Files...
}

Delete File

Parameters

Type

fileId

string

Response:

  • FileMetadataRes: The File metadata.

Example:

try {
    const result = await hat.files().deleteFile("file-id");

    if (result.parsedBody) {
        // result.parsedBody contains the File metadata.
    }
} catch (error) {
  // Failed to delete the File...
}

Generate File content URL

Parameters

Type

fileId

string

Response:

  • string: The URL to the content.

Example:

const url = hat.files().getFileContentUrl("file-id");

console.log(url); 
// will print:
// https://<hat-url>/api/v2.6/files/content/<file-id>>

// The file will be available in this URL.
// Note: if the file is private, will need to pass the authentication token as 
// a header to access the file.

Last updated 3 years ago

Was this helpful?