1.1.2 • Published 4 years ago
universal-file v1.1.2
title: file
universal-file
File operations.
Support
Install
$ npm install universal-file --save
Methods
getInfo(options)
Get file information.
Support
Parameters
Property | Type | Default | Required | Description | Support |
---|---|---|---|---|---|
filePath | String | √ | The file path | ||
digestAlgorithm | String | md5 | x | The algorithm to calculate the file summary can be md5, sha1 |
getSavedInfo(options)
Gets saved file information.
Support
Parameters
Property | Type | Default | Required | Description | Support |
---|---|---|---|---|---|
filePath | String | √ | The file path |
getSavedList(options)
Gets all saved file information.
Support
openDocument(options)
Open a file preview on the new page.
Support
Parameters
Property | Type | Default | Required | Description | Support |
---|---|---|---|---|---|
filePath | String | √ | The file path | ||
fileType | String | x | The file Type |
removeSaved(options)
Delete a saved file.
Support
Parameters
Property | Type | Default | Required | Description | Support |
---|---|---|---|---|---|
filePath | String | √ | The file path |
save(options)
Save the file locally.
Support
Parameters
Property | Type | Default | Required | Description | Support |
---|---|---|---|---|---|
filePath | String | √ | The file path |
upload(options)
Upload local resources to the developer server.
Support
Parameters
Property | Type | Default | Required | Description | Support |
---|---|---|---|---|---|
url | String | √ | Developer server address | ||
filePath | String | File Object | √ | The path to upload the file resource. In web browser, it can be either base64 string or a File object. | ||
fileName | String | √ | File name, that is, the corresponding key, the developer in the server side through this key can get the binary content of the file. | ||
fileType | String | √ | File type supports image, video, audio (image/video/audio). Not required in browser. | ||
header | Object | x | The HTTP request Header | ||
formData | Object | x | Additional form data in the HTTP request |
download(options)
Download file resources locally.
Support
Parameters
Property | Type | Default | Required | Description | Support |
---|---|---|---|---|---|
url | String | √ | Download file address | ||
header | Object | x | The HTTP request Header |
Example
import File from 'universal-file';
// Get file information.
File.getInfo({
filePath: 'https://resource/apml953bb093ebd2834530196f50a4413a87.video',
digestAlgorithm: 'sha1',
success: (res)=>{
console.log(JSON.stringify(res))
}
});
// You need to save the address to be able to use File.getsavedinfo
File.getSavedInfo({
filePath: '**filePath**',
success: (res) => {
console.log(res.size);
console.log(res.createTime);
}
});
File.getSavedList({
success:(res) => {
console.log(JSON.stringfy(res));
}
});
File.openDocument({
filePath: '**filePath**',
fileType: 'pdf',
success: (res) => {
console.log('open document success');
};
});
File.removeSaved({
filePath: '**filePath**',
success:(res) => {
console.log('remove success');
}
});
File.save({
filePath: '**filePath**',
success:(res) => {
console.log('save success');
}
});
File.upload({
url: 'http://httpbin.org/post',
fileType: 'image',
fileName: 'file',
filePath: '**filePath**',
success: res => {
console.log('upload success');
},
fail: res => {
console.log('upload succefailss');
},
});
File.download({
url: 'http://img.alicdn.com/tfs/TB1x669SXXXXXbdaFXXXXXXXXXX-520-280.jpg',
success: res => {
console.log(res.filePath);
},
fail: res => {
console.log(res);
},
});
2.0.0-beta
4 years ago
1.1.2
4 years ago
1.1.1
4 years ago
1.1.0
4 years ago
1.0.0
5 years ago
1.0.0-beta.1
5 years ago