Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@web-lite/storage

Package Overview
Dependencies
Maintainers
6
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@web-lite/storage

TypeScript client for Weblite S3 Storage

  • 0.0.91
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
10
increased by900%
Maintainers
6
Weekly downloads
 
Created
Source

Weblite Storage Client

TypeScript client for Weblite S3 Storage

API

declare const upload: (file: File, { name, type, meta, accessToken, compression, onProgress, }?: { 
  name?: string; // default: file.name
  type?: 'file' | 'voice' | 'image' | 'infer'; // default: `file`
  meta?: Record<string, unknown>; // use it carefully!
  compression?: CompressorOptions; // applied only if `type` = `image`, will be passed to compressorjs
  accessToken?: string; // if provided, will overwrite `config.authToken`
  onUploadSubmit?: (fileId: string) => void, // called when the upload is submitted in the queue
  onUploadStart?: (fileId: string) => void, // called when the upload is started
  onProgress?: (fileId: string, { sent, total }: {
    sent: number;
    total: number;
  }) => void;
}) => Promise<{
  fileId: string;
  fileName: string;
  size: number;
  type: 'file' | 'voice' | 'image';
  contentType: string;
  createdAt: Date;
}>

/*
returns `true` if successfully canceled
returns `false` if:
 - file has been completely uploaded
 - file has been already canceled
 - fileId is not valid
*/
declare const cancelUpload: (fileId: string) => boolean

// returns direct download link
declare const getDirectLink: (fileId: string) => string

// returns pre-signed download url
declare const getPreSignedDownloadUrl: (fileId: string, accessToken?: string) => Promise<string> 

declare const getInfo: (fileId: string, accessToken?: string) => Promise<{
  fileName: string;
  size: number;
  contentType: string;
  meta: Record<string, unknown>;
  directLink: string;
}>

declare const config: (values: {
  fileServiceUrl?: string
  s3Url?: string
  authToken?: string
}) => void

Usage

import * as storage from '@web-lite/storage'

storage.config({ authToken: 'yourAuthToken' })

const uploadImage = async (image: File): Promise<void> => {
  const { fileId } = await storage.upload(image, {
    type: 'image',
    compression: { quality: 0.5 },
  })

  const info = await storage.getInfo(fileId)
  console.log(info)
} 

const image = selectImage()
uploadImage(image)

Keywords

FAQs

Package last updated on 23 May 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc