LogoLogo
  • Home
  • Overview
  • Getting Started
  • Prompt Guide
  • API Reference
    • Authentication
      • Web3
      • Google OAuth
    • Account
    • Escrow
    • File upload
    • Wallet
Powered by GitBook
On this page
Export as PDF
  1. API Reference

File upload

This section explains uploading a file to the chainsite storage.

PreviousEscrowNextWallet

Last updated 3 days ago

Chainsites are deployed with storage in mind, ensuring users can upload files to the chainsite storage server.

The maximum uploaded file size can be adjusted at the Pakt Command Centre.

The following services are offered in this section

Upload Public File
Upload Private File
List User Files
Get File Details
Generate File Download URL

List User Files

get

The endpoint returns information about files that have been uploaded to the system, allowing users to browse through their uploaded content. The results are paginated to manage large collections of files efficiently.

Request

Query Parameters

  • page: Specifies which page of results to retrieve. In this example, page=1 requests the first page of results.

  • limit: Determines how many file records to return per page. In this example, limit=1 restricts the response to just one file record.

Response

The response provides a paginated list of file records along with pagination metadata:

Status Information

  • status: Indicates the outcome of the request. A value of "success" means the request was processed without errors.

  • message: Provides additional context about the request result. "OK" confirms that the operation completed as expected.

Pagination and Results Data

The "data" field contains both pagination information and the actual file records:

  • count: The total number of file records available across all pages. In this example, there are 2 total files in the system.

  • pages: The total number of pages available based on the requested limit. With 2 total files and a limit of 1 file per page, there are 2 pages available.

  • data: An array containing the file records for the current page. Since the limit is set to 1, this array contains only one file record:

    • _id: A unique database identifier for the file record, formatted as a MongoDB ObjectId.

    • name: The storage path and filename of the file in the storage system, including directory structure, user identifier, and a system-generated UUID filename with extension.

    • uploaded_by: The unique identifier of the user who uploaded the file, allowing for ownership tracking and permission management.

    • type: The MIME type of the file, indicating its format (in this case, "image/png" for a PNG image).

    • size: The size of the file in bytes, useful for tracking storage usage.

    • bucket: The storage bucket where the file is stored, in this case "chainsite-dev-storage" indicates a development environment.

    • url: A publicly accessible URL where the file can be viewed or downloaded. Note that in this example, the URL appears to be partially redacted or malformed with a hyphen replacing the domain.

    • meta: Additional metadata about the file:

      • originalName: The original filename from the user's system before upload, preserved for reference.

    • status: A boolean flag indicating whether the file is active and available (true) or not.

    • deletedAt: Timestamp indicating when the file was deleted. A null value means the file is not deleted.

    • createdAt: The timestamp when the file was uploaded and the record was created.

    • updatedAt: The timestamp when the file record was last modified.

    • __v: A version number for the document, used internally by MongoDB.

Usage

This endpoint is typically used to build file management interfaces, allowing users to browse, search, or manage their previously uploaded files. The pagination parameters (page and limit) enable efficient navigation through large collections of files.

By adjusting the page and limit parameters, users can retrieve different subsets of their uploaded files. For example, increasing the limit would show more files per page, while incrementing the page number would navigate through the collection.

The count and pages values help applications build appropriate pagination controls, showing users how many total files exist and how many pages they can navigate through.

Authorizations
Query parameters
pageintegerOptionalExample: 1
limitintegerOptionalExample: 10
coinNamestringOptionalExample: GOGOPOOL
Responses
200
OK
application/json
Responseobject
get
GET /v1/upload/ HTTP/1.1
Host: {{baseurl}}
Authorization: Bearer YOUR_SECRET_TOKEN
Accept: */*
200

OK

{
  "status": "success",
  "message": "OK",
  "data": {
    "count": 2,
    "pages": 2,
    "data": [
      {
        "_id": "68123badaa855ca20cdf6451",
        "name": "public/680b8f5b03127a4fd7110e38/d4a6e766-4157-4a9b-9e4e-d1bccd473bae.png",
        "uploaded_by": "680b8f5b03127a4fd7110e38",
        "type": "image/png",
        "size": "383373",
        "bucket": "chainsite-dev-storage",
        "url": "https://-/public/680b8f5b03127a4fd7110e38/d4a6e766-4157-4a9b-9e4e-d1bccd473bae.png",
        "meta": {
          "originalName": "80:20 rule.png"
        },
        "status": true,
        "deletedAt": null,
        "createdAt": "2025-04-30T15:03:09.568Z",
        "updatedAt": "2025-04-30T15:03:09.568Z",
        "__v": 0
      }
    ]
  }
}

Get File Details

get

The endpoint returns comprehensive metadata for a single file that has been previously uploaded to the system. This allows users or applications to access specific file details when the file ID is known.

Request

Path Parameters

  • id: The unique identifier of the file to retrieve. This is typically a MongoDB ObjectId that is assigned to the file record when it is created in the database.

Response

The response provides detailed information about the requested file:

Status Information

  • status: Indicates the outcome of the request. A value of "success" means the file was found and the information was retrieved without errors.

  • message: Provides additional context about the request result. "Success" confirms that the operation completed as expected.

File Data

The "data" field contains comprehensive metadata about the requested file:

  • _id: The unique database identifier for the file record that was used in the request. This matches the ID provided in the request path.

  • name: The storage path and filename of the file in the storage system. This structured path includes a public directory, the user identifier who uploaded the file, and a system-generated UUID filename with extension to ensure uniqueness.

  • uploaded_by: The unique identifier of the user who uploaded the file. This ID can be used to associate the file with a specific user account for ownership and access control purposes.

  • type: The MIME type of the file, which identifies its format and how it should be handled by applications. In this example, "image/png" indicates a PNG image file.

  • size: The size of the file in bytes. This information is useful for storage management and bandwidth considerations when accessing the file.

  • bucket: The cloud storage bucket where the file is stored. "chainsite-dev-storage" indicates this file is stored in a development environment bucket.

  • url: A publicly accessible URL where the file can be viewed or downloaded. Note that in this example, the URL appears to be partially redacted or malformed with a hyphen replacing the domain portion.

  • meta: Additional metadata about the file:

    • originalName: The original filename from the user's system before it was uploaded and renamed. This helps maintain a connection to the file's origin.

  • status: A boolean flag indicating whether the file is active and available (true) or not. This can be used to filter out inactive files without physically deleting them.

  • deletedAt: Timestamp indicating when the file was soft-deleted, if applicable. A null value means the file is not deleted and is still active in the system.

  • createdAt: The timestamp when the file was originally uploaded and the record was created in the database.

  • updatedAt: The timestamp when the file record was last modified. In this example, it matches the creation time, indicating the file hasn't been updated since upload.

  • __v: A version number for the document, used internally by MongoDB for concurrency control.

Usage

This endpoint is typically used when specific file information is needed, such as:

  • Displaying detailed file information in a management interface

  • Verifying file properties before processing

  • Retrieving the access URL to embed or link to the file in applications

  • Checking file metadata like size and type before performing operations on the file

The endpoint is particularly useful when building file management systems where users need to access, view, or manage individual files by their unique identifiers.

Authorizations
Path parameters
idstringRequiredExample: 68123badaa855ca20cdf6451
Responses
200
OK
application/json
Responseobject
get
GET /v1/upload/{id} HTTP/1.1
Host: {{baseurl}}
Authorization: Bearer YOUR_SECRET_TOKEN
Accept: */*
200

OK

{
  "status": "success",
  "message": "Success",
  "data": {
    "_id": "68123badaa855ca20cdf6451",
    "name": "public/680b8f5b03127a4fd7110e38/d4a6e766-4157-4a9b-9e4e-d1bccd473bae.png",
    "uploaded_by": "680b8f5b03127a4fd7110e38",
    "type": "image/png",
    "size": "383373",
    "bucket": "chainsite-dev-storage",
    "url": "https://-/public/680b8f5b03127a4fd7110e38/d4a6e766-4157-4a9b-9e4e-d1bccd473bae.png",
    "meta": {
      "originalName": "80:20 rule.png"
    },
    "status": true,
    "deletedAt": null,
    "createdAt": "2025-04-30T15:03:09.568Z",
    "updatedAt": "2025-04-30T15:03:09.568Z",
    "__v": 0
  }
}

Generate File Download URL

get

Unlike the other file-related endpoints that return metadata about the file, this endpoint generates and returns a pre-signed URL that provides temporary direct access to the file stored in AWS S3. This URL contains authentication credentials embedded as query parameters that allow temporary access to the file without requiring the requester to have AWS credentials.

Request

  • id: The unique identifier of the file to retrieve. This is typically a MongoDB ObjectId that is assigned to the file record when it is created in the database.

Response

A successful request returns a JSON response with the following structure:

The response provides a pre-signed URL for file download:

Status Information

  • status: Indicates the outcome of the request. A value of "success" means the download URL was generated successfully.

  • message: Provides additional context about the request result. "Success" confirms that the operation completed as expected.

File Access URL

  • data: Unlike the file metadata retrieval endpoint with the same path, this variant returns a direct string value containing a pre-signed Amazon S3 URL. This URL contains several key components:

    • Base URL: The S3 bucket location where the file is stored

    • Object Path: The path to the specific file within the bucket ("public/680b8f5b03127a4fd7110e38/d4a6e766-4157-4a9b-9e4e-d1bccd473bae.png")

    • Authentication Parameters: Several query parameters that authenticate and secure the request:

      • X-Amz-Algorithm: The signing algorithm used (AWS4-HMAC-SHA256)

      • X-Amz-Content-Sha256: Content hash value

      • X-Amz-Credential: The AWS access key ID and scope information

      • X-Amz-Date: The timestamp of when the URL was generated

      • X-Amz-Expires: The duration in seconds that the URL remains valid (300 seconds or 5 minutes)

      • X-Amz-Signature: A cryptographic signature that verifies the request

      • X-Amz-SignedHeaders: The headers included in the signature calculation

      • Additional Parameters: Extra parameters like checksum mode and object ID

Authorizations
Path parameters
idstringRequiredExample: 68123badaa855ca20cdf6451
Responses
200
OK
application/json
Responseobject
get
GET /v1/upload/url/{id} HTTP/1.1
Host: {{baseurl}}
Authorization: Bearer YOUR_SECRET_TOKEN
Accept: */*
200

OK

{
  "status": "success",
  "message": "Success",
  "data": "https://chainsite-dev-storage.s3.us-east-1.amazonaws.com/public/680b8f5b03127a4fd7110e38/d4a6e766-4157-4a9b-9e4e-d1bccd473bae.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIARSDEU2LVUTSZXUR4%2F20250430%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20250430T151722Z&X-Amz-Expires=300&X-Amz-Signature=7e562b30ffb1297d494f5c5ad026c79e3720ea19970ad89ace5ff6a2bb282802&X-Amz-SignedHeaders=host&x-amz-checksum-mode=ENABLED&x-id=GetObject"
}
  • POSTUpload Public File
  • POSTUpload Private File
  • GETList User Files
  • GETGet File Details
  • GETGenerate File Download URL

Upload Public File

post

This endpoint is used to upload a file for public purposes.

Request

Headers

  • Content-Type: multipart/form-data

Body

The request body should be formatted as multipart/form-data with the file to be uploaded included as a form field.

Response

  • status: Indicates the outcome of the upload operation. A value of "success" means the file was successfully uploaded and stored in the system.

  • message: Provides a human-readable description of the result. "file Uploaded Successfully" confirms that the operation completed as expected.

The "data" field contains comprehensive metadata about the uploaded file:

  • name: The storage path and filename of the uploaded file in the storage system. This includes a public directory path, user identifier, and a system-generated UUID filename with extension (e.g., "public/680b8f5b03127a4fd7110e38/ac5af6e7-08f2-42d0-9900-fdb729c82951.png").

  • uploaded_by: The unique identifier of the user who uploaded the file. This helps track file ownership and permissions within the system.

  • type: The MIME type of the uploaded file, which identifies the format and nature of the file (e.g., "image/png" for PNG images).

  • size: The size of the uploaded file in bytes. This can be useful for tracking storage usage and implementing file size limitations.

  • bucket: The storage bucket where the file is stored. In this example, "chainsite-dev-storage" indicates this is stored in a development environment bucket.

  • url: A publicly accessible URL where the file can be viewed or downloaded. This URL uses a content delivery network (CloudFront) to ensure fast access globally.

  • meta: Additional metadata about the file:

    • originalName: The original filename from the user's system before it was uploaded and renamed.

  • status: A boolean flag indicating whether the file is active and available (true) or not.

  • deletedAt: Timestamp indicating when the file was deleted. A null value means the file is not deleted.

  • _id: A unique database identifier for the file record, typically in MongoDB ObjectId format.

  • createdAt: The timestamp when the file was uploaded and the record was created.

  • updatedAt: The timestamp when the file record was last modified.

Usage Notes

  1. The uploaded file is immediately available at the URL provided in the response.

  2. The system automatically generates a unique identifier for each file to prevent name collisions.

  3. Original filenames are preserved in metadata but not used in the actual storage path.

  4. The response includes all necessary information to reference the file in future API calls.

Authorizations
Body
filestring · binaryOptional
Responses
200
OK
application/json
Responseobject
post
POST /v1/upload HTTP/1.1
Host: {{baseurl}}
Authorization: Bearer YOUR_SECRET_TOKEN
Content-Type: multipart/form-data
Accept: */*
Content-Length: 17

{
  "file": "binary"
}
200

OK

{
  "status": "success",
  "message": "file Uploaded Successfully",
  "data": {
    "name": "public/680b8f5b03127a4fd7110e38/ac5af6e7-08f2-42d0-9900-fdb729c82951.png",
    "uploaded_by": "680b8f5b03127a4fd7110e38",
    "type": "image/png",
    "size": "383373",
    "bucket": "chainsite-dev-storage",
    "url": "https://d2m11zsaax1wy8.cloudfront.net/public/680b8f5b03127a4fd7110e38/ac5af6e7-08f2-42d0-9900-fdb729c82951.png",
    "meta": {
      "originalName": "80:20 rule.png"
    },
    "status": true,
    "deletedAt": null,
    "_id": "68123dd4aa855ca20cdf6471",
    "createdAt": "2025-04-30T15:12:20.054Z",
    "updatedAt": "2025-04-30T15:12:20.054Z",
    "__v": 0
  }
}

Upload Private File

post

Upload a file privately. Use this endpoint if the file is sensitive or needs to be private.

Headers

  • Content-Type: multipart/form-data

Body

The request body should be formatted as multipart/form-data with the file to be uploaded included as a form field.

Response

  • status: Indicates the outcome of the upload operation. A value of "success" means the file was successfully uploaded and stored in the system.

  • message: Provides a human-readable description of the result. "file Uploaded Successfully" confirms that the operation completed as expected.

File Data

The "data" field contains comprehensive metadata about the uploaded file:

  • name: The storage path and filename of the uploaded file in the storage system. This includes a public directory path, user identifier, and a system-generated UUID filename with extension (e.g., "public/680b8f5b03127a4fd7110e38/ac5af6e7-08f2-42d0-9900-fdb729c82951.png").

  • uploaded_by: The unique identifier of the user who uploaded the file. This helps track file ownership and permissions within the system.

  • type: The MIME type of the uploaded file, which identifies the format and nature of the file (e.g., "image/png" for PNG images).

  • size: The size of the uploaded file in bytes. This can be useful for tracking storage usage and implementing file size limitations.

  • bucket: The storage bucket where the file is stored. In this example, "chainsite-dev-storage" indicates this is stored in a development environment bucket.

  • url: A publicly accessible URL where the file can be viewed or downloaded. This URL uses a content delivery network (CloudFront) to ensure fast access globally.

  • meta: Additional metadata about the file:

    • originalName: The original filename from the user's system before it was uploaded and renamed.

  • status: A boolean flag indicating whether the file is active and available (true) or not.

  • deletedAt: Timestamp indicating when the file was deleted. A null value means the file is not deleted.

  • _id: A unique database identifier for the file record, typically in MongoDB ObjectId format.

  • createdAt: The timestamp when the file was uploaded and the record was created.

  • updatedAt: The timestamp when the file record was last modified.

Usage Notes

  1. The uploaded file is immediately available at the URL provided in the response.

  2. The system automatically generates a unique identifier for each file to prevent name collisions.

  3. Original filenames are preserved in metadata but not used in the actual storage path.

  4. The response includes all necessary information to reference the file in future API calls.

  5. This endpoint is for uploading private files that the user does not want shared with others.

Authorizations
Body
filestring · binaryOptional
Responses
undefined
text/plain
Responsestring
post
POST /v1/upload/private HTTP/1.1
Host: {{baseurl}}
Authorization: Bearer YOUR_SECRET_TOKEN
Content-Type: multipart/form-data
Accept: */*
Content-Length: 17

{
  "file": "binary"
}
undefined
{
    "status": "success",
    "message": "file Uploaded Successfully",
    "data": {
        "name": "private/680b8f5b03127a4fd7110e38/ac5af6e7-08f2-42d0-9900-fdb729c82951.png",
        "uploaded_by": "680b8f5b03127a4fd7110e38",
        "type": "image/png",
        "size": "383373",
        "bucket": "chainsite-dev-storage",
        "url": "https://d2m11zsaax1wy8.cloudfront.net/private/680b8f5b03127a4fd7110e38/ac5af6e7-08f2-42d0-9900-fdb729c82951.png",
        "meta": {
            "originalName": "80:20 rule.png"
        },
        "status": true,
        "deletedAt": null,
        "_id": "68123dd4aa855ca20cdf6471",
        "createdAt": "2025-04-30T15:12:20.054Z",
        "updatedAt": "2025-04-30T15:12:20.054Z",
        "__v": 0
    }
}