JavaScript is a general-purpose, cross-platform, vlocation-neutral scripting language, which originated from users’ strong demand for browser interaction experience. With the development and progress of the Internet, versions of JavaScript continue to iterate to provide more and more rich functions, and constantly improve the user experience.

Better JavaScript SDK

Before the advent of H5 File API, the front-end operation of files is very limited, often rely on Flash to handle File operations, most of which need to cooperate with the back-end implementation. For security reasons, when uploading a file from a local location, it’s impossible for the code to get the local address of the file, so it’s impossible for the pure front end to do something like image preview.

Our older version of JavaScript SDK was limited by the historical environment at the time, but it was barely usable, and the user experience was a constant regret of our developer. We are committed to providing users with simple, reliable services, and we want users to experience the SDK tools as easy to use and efficient. Naturally, with the maturing of H5 File API technology, we upgraded and iterated the JavaScript SDK at the first time after full verification of internal discussions. And has been released recently, updated information as follows:

  • Based on native browser API, portable:

Applicable to Internet Explorer 11, Edge, Chrome, Firefox, Safari and other browsers. Built based on the official QIuniuyun API, the upload function is based on the H5 File API. Based on JS-SDK, developers can easily upload files from the browser to Qiniuyun, and carry out rich data processing operations on the pictures uploaded successfully.

  • The API is simple and clear:

We refer to the interface design mode of RxJS. The interface of the new SDK is very simple. Users can directly set corresponding parameters in Config and putExtra.

  • Concurrency control:

The old SDK was synchronous serial when uploading fragments, and other pieces had to wait for the previous piece to be uploaded successfully before uploading, which actually wasted time and reduced the resource utilization of the browser. Therefore, in the new SDK, we optimized the fragment upload into concurrency, and added concurrency control. Users can set the number of concurrent requests through config.thread. Achieving the maximum concurrency depends only on the limitations of the browser the user is using.

  • Md5 check:

The new SDK provides MD5 verification. Users do not need to worry about the error file generated when the file is not uploaded successfully. Users can use config.checkByMD5 to set whether md5 verification is enabled.

  • Combined API with third-party plugins to achieve compatibility with older browsers:

Js-sdk is compatible with browsers that support H5 File API. In earlier versions of browsers, additional plug-ins such as Plupload are required. Js-sdk provides some interfaces for uploading with plug-ins. We stripped out the reference of the plug-in in the new SDK. For users who need to be compatible with the browser of the lower version, they can reference the plug-in themselves and develop with the interface provided by the new SDK.

  • Optimization of image processing:

The SDK provides image processing interfaces such as watermark, thumbnail, rotation, etc., and optimizes the original asynchronous request interface based on the old version with Promise. You can visit the Demo to try out our Demo.

The effects of uploading and processing pictures are as follows:

The new JavaScript SDK currently supports a variety of installation methods, users can choose according to their own development habits:

1. Use static file address directly:

https://unpkg.com/qiniu-js@<version>/dist/qiniu.min.js
Copy the code

Importing this file with the SCtipt tag generates an object named qiniu globally.

2. Install using NPM

NPM, or Node Package Manager, is a NodeJS Package management and distribution tool that has become the standard for unofficial distribution of Node modules (packages). For more detailed instructions on the use of NPM, you can visit the official website of NPM or its Corresponding Chinese website.

npm install qiniu-js
Copy the code

var qiniu = require("qiniu.js")
// or

import * as qiniu from "qiniu-js"
Copy the code

3. Compile from source code

Git clone [email protected]:qiniu/js-sdk.git, go to the root directory of the project, execute NPM install, execute NPM run build, and generate qiniu.min.js in dist directory.

Visit our documentation site or Fork GitHub to learn more

Follow the public account qi Niuyun for more information