Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
npm i qiniu-js@^4.0.0
import { createDirectUploadTask, createMultipartUploadV2Task, FileData } from 'qiniu-js';
// 创建上传数据
const fileData: FileData = { type: 'file', data: File}
const fileData: FileData = { type: 'string', data: 'content' }
const fileData: FileData = { type: 'array-buffer', data: new ArrayBuffer(1e3) }
// 创建直传任务
const uploadTask = createDirectUploadTask(fileData, config);
// 创建分片上传任务
// 部分私有云服务版本较老的请使用 v1 分片上传
const uploadTask = createMultipartUploadV2Task(fileData, config);
// 设置进度回调函数
uploadTask.onProgress((progress, context) => {
// 处理进度回调
});
// 设置完成回调函数
uploadTask.onComplete((result, context) => {
// 处理完成回调
});
// 设置错误回调函数
uploadTask.onError((error, context) => {
// 处理错误回调
});
uploadTask.start()
如果你不需要关心进度信息,可以通过 start 快速获取任务的状态信息
createMultipartUploadTask(fileData, config).start()
.then((result) => {
// 处理任务完成结果
})
.catch((error) => {
// 处理任务启动失败错误
});
type TokenProvider = () => Promise<string>
interface Context<ProgressKey extends string = string> {
host?: Host;
token?: Token;
result?: string;
error?: UploadError;
progress: Progress<ProgressKey>;
}
host
:上传使用的 host。token
:上传使用的 token。result
:上传成功的信息。error
:队列的错误。progress
:整体的任务进度信息。interface UploadConfig {
tokenProvider: TokenProvider;
apiServerUrl?: string;
uploadHosts?: []string;
logLevel?: LogLevel;
protocol?: HttpProtocol;
vars?: Record<string, string>;
}
apiServerUrl
:服务的接口地址;默认为七牛公有云,示例:https://api.qiniu.com 该配置仅当未设置 uploadHosts
时生效,SDK 将会通过指定的 api 服务提供的接口来动态获取上传地址,私有云请联系集群运维人员,并确认集群是否支持 v4/query
接口uploadHosts
: 上传服务地址,手动指定上传服务地址,示例:up.qiniu.comlogLevel
:日志级别。protocol
:HTTP 协议,默认 HTTPS。tokenProvider
:用于获取上传所需 token 的函数。vars
: 上传过程中的自定义变量。type OnError = (error: UploadError, context: Context) => void;
type OnProgress = (progress: Progress, context: Context) => void;
type Progress<Key extends string = string> = {
/** 上传的文件总大小;单位 byte */
size: number
/** 目前处理的百分比进度;范围 0-1 */
percent: number
/** 具体每个部分的进度信息; */
details: Record<Key, {
/** 子任务的处理数据大小;单位 byte */
size: number
/** 目前处理的百分比进度;范围 0-1 */
percent: number
/** 该处理是否复用了缓存; */
fromCache: boolean
}>
}
type OnComplete = (result: string, context: Context) => void;
void
。interface UploadTask {
onProgress(fn: OnProgress): void;
onComplete(fn: OnComplete): void;
onError(fn: OnError): void;
cancel(): Promise<Result>;
start(): Promise<Result>;
}
onProgress(fn: OnProgress)
:设置进度回调函数。onComplete(fn: OnComplete)
:设置完成回调函数。onError(fn: OnError)
:设置错误回调函数。cancel()
:取消上传任务,并返回一个 Promise,该 Promise 在解析时提供任务结果。start()
:启动上传任务,并返回一个 Promise, 该 Promise 在解析时提供任务结果。FAQs
Qiniu browser upload sdk
The npm package qiniu-js receives a total of 1,678 weekly downloads. As such, qiniu-js popularity was classified as popular.
We found that qiniu-js demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
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.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.