storage.vault.get将带回同一文件

时间:2019-06-08 09:37:36

标签: amazon-web-services react-native

我已经使用AWS Amplify构建了一个无服务器移动应用程序,对本机和Cognito Auth做出反应。到目前为止,该应用程序允许用户使用从Cognito创建的凭据登录。然后该应用程序允许用户扫描QR码,该QR码将返回存储在S3存储桶中的信息(信息显示在应用程序外部的互联网浏览器上)。目前一切成功。但是,当我将存储桶设为私有(这是必不可少的)并在代码中使用Storage.Vault.Get方法时,它只会从存储桶中带回一个私有对象/文件。

类应用扩展了React.Component {

constructor(){

 super()

 this.state = {

   //variable to hold the qr value

   data: '',

   fileurl: '',

   file: '',

   opneScanner: false,

 };

}

onOpenlink(){

 //Function to open URL, If scanned

 Linking.openURL(this.state.fileurl);

 //Linking used to open the URL in any browser that you have installed

}

onBarcodeScan(data){

 //called after te successful scanning of QRCode/Barcode

 this.setState({ data: data });

 this.setState({ opneScanner: false });

}

onOpneScanner(){

 var that =this;

 //To Start Scanning

 if(Platform.OS === 'android'){

   async function requestCameraPermission() {

     try {

       const granted = await PermissionsAndroid.request(

         PermissionsAndroid.PERMISSIONS.CAMERA,{

           'title': 'Code Blue App Camera Permission',

           'message': 'Code Blue App needs access to your camera '
         }

       )

       if (granted === PermissionsAndroid.RESULTS.GRANTED) {

         //If CAMERA Permission is granted

         that.setState({ data: '' });

         that.setState({ opneScanner: true });

       } else {

         alert("CAMERA permission denied");

       }

     } catch (err) {

       alert("Camera permission err",err);

       console.warn(err);

     }

   }

   //Calling the camera permission function

   requestCameraPermission();

 }else{

   that.setState({ data: '' });

   that.setState({ opneScanner: true });

 }

}

getData(){

Storage.vault.get('John.pdf') 

.then(data => { 

   this.setState({

     fileurl: data

   }) 

 });  

 Storage.vault.get('Mike.pdf')

.then(data => { 

   this.setState({

     fileurl: data

   }) 

 });   

}

componentDidMount(){

this.getData();   

this.timer = setInterval(() => this.getData(), 5000);

}

componentWillUnmount(){

clearInterval(this.timer);

this.timer = null;

}

render(){

 let displayModal;

 //If data is set then return this view

 if (!this.state.opneScanner) {

   return ( 

     <View style={styles.container}>

         <Text style={styles.heading}>MySay QR Scanner</Text>

         <Text style={styles.simpleText}>{this.state.data ? 'Scanned QR 

代码:“ + this.state.data:”}

         {this.state.data.includes("http") ?

           <TouchableHighlight

             onPress={() => this.onOpenlink()}

             style={styles.button}>

               <Text style={{ color: '#FFFFFF', fontSize: 14 }}>Open 

链接

           </TouchableHighlight>

           : null

         }

         <TouchableHighlight

           onPress={() => this.onOpneScanner()}

           style={styles.button}>

             <Text style={{ color: '#FFFFFF', fontSize: 14 }}>

             Open QR Scanner

             </Text>

         </TouchableHighlight>

     </View>
   );
 }
 return (
   <View style={{ flex: 1 }}>
     <CameraKitCameraScreen
       showFrame={false}
       //Show/hide scan frame
       scanBarcode={true}
       //Can restrict for the QR Code only
       laserColor={'blue'}
       //Color can be of your choice
       frameColor={'yellow'}
       //If frame is visible then frame color
       colorForScannerFrame={'black'}
       //Scanner Frame color
       onReadCode={event =>
         this.onBarcodeScan(event.nativeEvent.codeStringValue)
       }
     />
   </View>
 );

}    }

0 个答案:

没有答案