Socket
Book a DemoInstallSign in
Socket

@aplus-frontend/oss

Package Overview
Dependencies
Maintainers
9
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aplus-frontend/oss

Rebuild ali-oss javascript sdk that provie private sts server methods

npmnpm
Version
1.0.0
Version published
Weekly downloads
121
-20.39%
Maintainers
9
Weekly downloads
 
Created
Source

APLUS OSS

Rebuild ali-oss javascript sdk that provie private sts server methods

Quick start

//add -w in you root folder
pnpm install @aplus-frontend/oss -S -w

Usage example

//register client instance
import { client } from '@aplus-frontend/oss'

//some code in you project
import { you_STS_server } from '@/api/sts'

//init oss access token
const ossIntsance = client.initOssClient({
  you_STS_server,
  onFailure: err => {
    console.warn('get oss accessSerct fail', err)
  }
})

//after init
//you can use ossIntsance do something

ossIntsance.put(..)
ossIntsance.getSignatureUrl(..)
ossIntsance.downloadFile(..)
ossIntsance.deleteFile(..)
ossIntsance.pauseUpload(...)


// upload image or vedio with oss
// your can use put method to upload
const result = await client.put({
  fileName: file.name,
  dirName: 'Vedio',
  data: file,
  progressCallBack: (p: number) => {
    percentVeido.value = p
  },
  //the number of parts to be uploaded in parallel
  parallel: 6,
  //the suggested size for each part, defalut 1024 * 1024(1MB), minimum 100 * 1024(100KB)
  partSize: 1024 * 1024
})

if (result.status === 200) {
  const { status, previewUrl, saveUrl } = result
  console.log('status---', status)
  console.log('previewUrl---', previewUrl)
  console.log('saveUrl---', saveUrl)
} else {
  //failure
  console.log(result.message)
}

//you can use download method to download
let res = client.downloadFile(fileName)
console.log(res.message)
console.log(res.status)
//you can  get signature url to perview with  getSignatureUrl method
let signatureUrl = client.getSignatureUrl(pathName)
//get signature url
//after expires seconds, the url will become invalid, default is 3600s
console.log(signatureUrl)

//delete file
let res = await client.deleteFile(pathName)
console.log(res)

//pauseUpload
let res = = await client.pauseUpload()
console.log(res)

Methods

initOssClient

type: initOssClient(options: ResquestOssOptions): Promise<Oss>;

tips: register client instance with you sts server

ResquestOssOptions

propstypedefaultdirections
getOssAccess() => Promise<accessCreate>-init oss access token
onFailure(err: any) => void-get oss accessSerct fail

put

type: put({ fileName, dirName, data, progressCallBack, parallel, partSize }: uploadParams): Promise<actionResponse>;

tips: you can put image vedio with put core method

options

PropsTypedefaultexplanation
fileNamestring-file Name
dirNamestring-upload folder name
dataFile-upload data
progressCallBack(p:number) => void-upload progress
parallelnumber6the number of parts to be uploaded in parallel
partSizenumber1024*1024(1M)the suggested size for each part, defalut 1024 _ 1024(1MB), minimum 100 _ 1024(100KB)

actionResponse

PropsTypedefaultexplanation
statusnumber-status code(success 200 ,other will be fail)
previewUrlstring-preview file url,you can preview image or vedio after uploaded
saveUrlstring-your backend server wille be save this path
messagestring-success message or fail message

downloadFile

type: downloadFile(savePathName: Array<string> | string): Promise<actionResponse>;

tips: dowload file with downloadFile method (support multiple download files)

options

PropsTypedefaultexplanation
savePathNameArray<string> | string-if mutipart download will be arrary,single file download wille be string

actionResponse

PropsTypedefaultexplanation
statusnumber-status code(success 200 ,other will be fail)
previewUrlstring-preview file url,you can preview image or vedio after uploaded
saveUrlstring-your backend server wille be save this path
messagestring-success message or fail message

getSignatureUrl

type: getSignatureUrl(name: string, expires?: number): Promise<string>;

tips: get signature url to perview

options

PropsTypedefaultexplanation
namestring-file path name
expiresnumber3600(s)expires time

deleteFile

type: deleteFile(savePathName: string): Promise<{status: any;message: string;} | undefined>;

tips: delete oss file options

PropsTypedefaultexplanation
savePathNamestring-file path name

pauseUpload

type: pauseUpload(): Promise<{status: number;message: globMessage;}>

tips: pause upload

Keywords

@aplus-frontend

FAQs

Package last updated on 17 May 2024

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