aliyun-oss-react-native

DownloadManager.js 1.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import React, { Component } from 'react';
  2. import {
  3. Platform,
  4. StyleSheet,
  5. Text,
  6. View,
  7. Alert,
  8. Button,
  9. ScrollView,
  10. Image,
  11. DeviceEventEmitter
  12. } from 'react-native';
  13. //导入样式
  14. import { styles } from '../CSS/global.js'
  15. export class DownloadManager extends Component {
  16. render() {
  17. return (
  18. <View style={styles.item}>
  19. <Text style={styles.description}>文件下载</Text>
  20. <View style={styles.detailitem}>
  21. <View style={styles.button}>
  22. <Button
  23. onPress={this.handClick}
  24. title="下载文件"
  25. color="#841584"
  26. />
  27. </View>
  28. </View>
  29. </View>
  30. )
  31. }
  32. handClick() {
  33. console.log("准备下载")
  34. AliyunOSS.asyncDownload('luozhang002','yanxing').then((e)=>{
  35. Alert.alert(e)
  36. console.log(e)
  37. }).catch((e)=>{
  38. console.log(e)
  39. })
  40. }
  41. componentDidMount(){
  42. const downloadProgress = p => console.log(p.currentSize / p.totalSize);
  43. AliyunOSS.addEventListener('downloadProgress', downloadProgress);
  44. }
  45. }