Last update:2020-09-27 15:04:32
Notes:
There is no token creation module in Wcs-JavaScript-SDK. For more security, we suggest that customer should set up a server for token calculation.
<script type="text/javascript" src="/dist/wcs.min.js"></script>
Introduce the file via the script tag, and it will generate an object called WCS globally.
npm install wcs-js-sdk
import * as wangsu from 'wcs-js-sdk'
Other introduce methods:
1. import * as wangsu from 'wcs-js-sdk' call wangsu.wcsUpload()
2. import { wcsUpload } from 'wcs-js-sdk' call wcsUpload()
var uploadObj = wangsu.wcsUpload(file, token, uploadUrl, extraConfig);
Parameters:
file // The file need to be uploaded
token // Token required by the backend server
uploadUrl // Upload URL
extraConfig={
timeout: 0, //Timeout, default value is 0, it will retry upload when timeout
concurrentRequestLimit:3, //Concurrency, default value is 3. Notes: The browsers have limitation in the request resources for the connection. For example, Chrome's request limitation is 6, so there will be a situation where if you write 10 concurrently, but only 6 are actually uploaded.
retryCount:0 //Retry upload, default value is 0.
}
uploadObj.putFile();
uploadObj.uploadProgress = function (progress) {}
- progress format
{
total:{
loaded: ?, //Loaded size
size: ?, //Total file size
percent: ? //ratio
},
chunks:[ //Block info, it is in array format
{loaded: ?, size: ?, percent: ?},
{loaded: ?, size: ?, percent: ?}
]
}
uploadObj.onError = function (error) {}
- error format
{
code: ?, // Error code, please note that there isn't code in uploadObj.stop() and timeout retry
message: "", //Error info
isRequestError: true //Is it a request error? That is, after normal upload, the server returns an error. This is a normal error, and there is no need to re-upload.
}
uploadObj.onComplete = function(res){}
- res format
{
data: jsonObj/String //The result returned by the server. Note: If the code string is returned directly, the JSON object is returned if the chunk size is exceeded and multipart uploads is used.
}
uploadObj.stop();