@gune/storage-local
v0.1.0
Published
Local filesystem storage strategy
Readme
@gune/storage-local
Local filesystem storage strategy for the Gune Storage system.
Installation
npm install @gune/storage-localUsage
Standalone
import { LocalStorageStrategy } from '@gune/storage-local';
const storage = new LocalStorageStrategy({
basePath: './uploads',
baseUrl: '/uploads',
});
// Upload a file
const result = await storage.store(
Buffer.from('Hello World'),
'hello.txt',
{ contentType: 'text/plain' }
);With NestJS
import { StorageModule } from '@gune/storage-nestjs';
import { LocalStorageStrategy } from '@gune/storage-local';
@Module({
imports: [
StorageModule.forRoot({
strategy: new LocalStorageStrategy({
basePath: './uploads',
baseUrl: '/uploads',
}),
}),
],
})
export class AppModule {}Configuration
LocalStorageStrategyConfig
basePath: Local directory to store files (e.g., './uploads')baseUrl: Base URL for accessing files (e.g., '/uploads' or 'https://example.com/files')ensureDir?: Automatically create directory if it doesn't exist (default: true)
Features
- File upload to local filesystem
- Stream support
- Organized file structure using date-based folders
- File retrieval
- File deletion
- Metadata support via JSON sidecar files
Use Cases
- Development and testing
- Small applications without cloud storage
- Temporary file storage
- Cache storage
Important Notes
- Not recommended for production use with horizontal scaling
- Requires proper file serving configuration (e.g., via Express static middleware)
- Make sure the application has write permissions to the storage directory
Serving Files with Express
import * as express from 'express';
import { join } from 'path';
app.use('/uploads', express.static(join(__dirname, '../uploads')));License
MIT © BUDDGUN92
