Registry / storage / qiniu-js

qiniu-js

JSON →
library3.4.4jsnpmunverified

Client-side JavaScript SDK for uploading files to Qiniu Cloud Storage directly from the browser. Current stable version is 3.4.4, with 4.x in beta (adding WebWorker, mini-program, Harmony support). Supports chunked upload for files >4MB with resume capability, and image processing (thumbnailing, watermarking, etc.). Requires a server-side token for authentication. Works in IE11+, Edge, Chrome, Firefox, Safari. Compared to alternatives like AWS SDK for S3, this is the official Qiniu SDK with native Chinese documentation and regional optimizations.

npm install qiniu-js
INSTALL
IMPORT
SIG · QINIU-JS
Q
qiniu-js
storagejavascriptv3.4.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

qiniu (namespace)
import * as qiniu from 'qiniu-js'
const qiniu = require('qiniu-js')
ESM is preferred. CommonJS require works but may have issues with bundlers. The module exports a namespace object, not a default export.
upload
import { upload } from 'qiniu-js'
import upload from 'qiniu-js'
upload is a named export, not default. Available since v3.
Observable
import { Observable } from 'qiniu-js'
Type import for the Observable type used by upload. Available in TypeScript typings.

Initializes an upload from a file input, fetches an upload token from server, and starts upload with progress logging.

import * as qiniu from 'qiniu-js'; const file = document.querySelector('input[type=file]').files[0]; const token = await fetch('/api/qiniu-token').then(r => r.text()); const observable = qiniu.upload(file, null, token, { fname: file.name, useCdnDomain: true }); const subscription = observable.subscribe({ next: (res) => { console.log('Upload progress', res.total); }, error: (err) => { console.error('Upload failed', err); }, complete: (res) => { console.log('Upload complete, key:', res.key); } }); // To cancel: // subscription.unsubscribe();
Debug
Known issues
breakingv3.0.0: Removed the old qiniu.uploader function and changed to rxjs-based observable pattern.
fix
Update code to use qiniu.upload with .subscribe() pattern. See migration guide at https://github.com/qiniu/js-sdk/wiki/2.x-升级到-3.x-文档注意事项
affects: >=3.0.0
breakingv3.2.0: Changed default domain setting; useCdnDomain now defaults to true.
fix
If you rely on the old default (false), explicitly set config.useCdnDomain: false.
affects: >=3.2.0
deprecatedv3.4.0: The method qiniu.getUploadUrl() is deprecated. Use the config options instead.
fix
Remove calls to getUploadUrl() and pass uploadUrl in the config object to qiniu.upload().
affects: >=3.4.0
gotchaIE11 requires babel-polyfill (or core-js/stable, regenerator-runtime) for Promise, Object.assign, etc.
fix
Add 'import "core-js/stable"; import "regenerator-runtime/runtime";' before importing qiniu-js.
affects: >=3.0.0
Errors
Common errors & fixes
Uncaught TypeError: qiniu.upload is not a function
Using default import instead of named import or namespace import.
fix
Use: import * as qiniu from 'qiniu-js' or const qiniu = require('qiniu-js')
TypeError: Cannot read property 'subscribe' of undefined
Upload token is expired or invalid, causing observable to return undefined.
fix
Ensure token is a valid uptoken string and not expired. Generate a new one from your server.
Module not found: Can't resolve 'rxjs'
In v3, rxjs is a peer dependency. It must be installed separately.
fix
Run: npm install rxjs (version ^6.0.0 recommended)
Upgrade
Version history
3.4.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
30 hits · last 30 days
node
28
OpenAI (training)
1
Resources
qiniu-js — npm install qiniu-js · libregistry