npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@krutai/uploadfile-services

v1.0.0

Published

Library to handle file uploads to AWS via ai_builder backend

Readme

@krutai/uploadfile-services

A TypeScript client library for uploading and retrieving files via the KrutAI backend, which stores files in S3-compatible storage (DigitalOcean Spaces / AWS S3) under a structured userId/projectId/ path.

Installation

npm install @krutai/uploadfile-services
# or
bun add @krutai/uploadfile-services

Configuration

The client is constructed with an UploadFileServiceClientConfig object:

| Option | Type | Required | Default | Description | |-------------------|-----------|----------|----------------------------|------------------------------------------------------------------------------| | apiKey | string | Yes* | process.env.KRUTAI_API_KEY | Your KrutAI API key. Falls back to the environment variable if not provided. | | serverUrl | string | No | http://localhost:8000 | Base URL of the KrutAI backend server. Trailing slashes are stripped. | | validateOnInit | boolean | No | true | Set to false to skip the async server-side API key validation step. |

Quick Start

import { UploadFileServiceClient } from '@krutai/uploadfile-services';

const client = new UploadFileServiceClient({
    apiKey: 'your-krutai-api-key',
    serverUrl: 'http://localhost:8000',
});

// Validate the API key against the server before making requests
await client.initialize();

Note: Every request automatically attaches the API key as both an Authorization: Bearer <key> header and an x-api-key header to the backend.

API

new UploadFileServiceClient(config)

Creates a new client instance. Performs a synchronous format check on the API key immediately. Throws a KrutAIKeyValidationError if the key format is invalid.

client.initialize(): Promise<void>

Validates the API key against the server (makes a network request). Must be called before any other method unless validateOnInit: false was passed to the constructor.

await client.initialize();

client.uploadFile(file, filename, userId, projectId): Promise<UploadFileResponse>

Uploads a file to the backend. The file is stored in S3 at the path:

{userId}/{projectId}/{timestamp}_{filename}

Parameters:

| Parameter | Type | Description | |-------------|---------------|------------------------------------------| | file | Blob \| File | The file content to upload | | filename | string | The desired name of the file | | userId | string | The ID of the user who owns the file | | projectId | string | The ID of the project the file belongs to |

Returns: Promise<UploadFileResponse>

interface UploadFileResponse {
    message: string;  // Success message from the server
    fileUrl: string;  // Public or signed URL to access the uploaded file
    path: string;     // The S3 key (e.g. "user123/proj456/1712345678_hello.txt")
}

Example:

const fileBlob = new Blob(['Hello, world!'], { type: 'text/plain' });

const response = await client.uploadFile(fileBlob, 'hello.txt', 'user123', 'project456');

console.log(response.message);  // "File uploaded successfully"
console.log(response.fileUrl);  // Accessible URL for the file
console.log(response.path);     // "user123/project456/1712345678_hello.txt"

client.getFile(key, fetchContent?): Promise<string | any>

Retrieves a file by its S3 key (the path returned by uploadFile).

Parameters:

| Parameter | Type | Default | Description | |----------------|-----------|---------|--------------------------------------------------------------------------------| | key | string | — | The S3 key of the file (e.g. value of response.path) | | fetchContent | boolean | false | If true, downloads and returns file content from the backend response. If false, returns just the URL string. |

Returns: Promise<string> when fetchContent is false, and Promise<any> when true (as currently typed by the client).

Examples:

// Get a direct URL to the file (no network request for the file itself)
const url = await client.getFile('user123/project456/1712345678_hello.txt');
console.log(url); // "https://your-backend.example.com/library/files?key=user123%2Fproject456%2F..."

// Download the actual file content from the backend response
const fileContent = await client.getFile('user123/project456/1712345678_hello.txt', true);
console.log(fileContent);

Skipping Initialization (Advanced)

If you are in an environment where the API key is known to be valid and you want to avoid the extra round-trip, pass validateOnInit: false:

const client = new UploadFileServiceClient({
    apiKey: process.env.KRUTAI_API_KEY!,
    serverUrl: 'https://your-backend.example.com',
    validateOnInit: false,
    // No need to call client.initialize()
});

const response = await client.uploadFile(file, 'report.pdf', 'user123', 'proj456');

Backend Endpoints Used

| Method | Endpoint | Description | |--------|-------------------|---------------------------------------------| | POST | /library/files | Upload a file (multipart/form-data) | | GET | /library/files | Retrieve a file or its URL using ?key= |