我创建了一个应用程序,可以拍照并上传到AWS s3。一旦捕获了这些,就需要对它们进行哈希处理。在那里,我使用了Base64哈希方法,并且捕获的照片被加密了。但是我无法打开它,也不确定是否以适当的方式完成了该操作。
在上传之前,我想取消这些哈希。也就是说,它们必须作为散列图像存储在图库中。但是,我想在上传之前将它们转换为原始图像。因此,我可以将真实图像存储在云中。
我的代码是
import React, {Component} from 'react';
import {Platform, StyleSheet,Alert, Text,TouchableOpacity, View,Picker,Animated,Easing,Image, NetInfo,
Dimensions,Button,ScrollView } from 'react-native';
import ImagePicker from 'react-native-image-picker';
import RNFS from 'react-native-fs';
class SecondScreen extends React.Component {
takePic = () => {
if(this.state.connection_Status==="Online"){
this.getServerTime();
try{
this.setState({capturedTime:this.state.serverTime.currentFileTime+'_'+time},
() => console.log(this.state.serverTime.currentFileTime)
);
} catch (err) {
var date = new Date();
var time = date.getTime();
this.setState({capturedTime:time});
console.log("localtime")
}
}
const options = {
quality: 1.0,
maxWidth: 75,
maxHeight: 75,
base64: true,
skipProcessing: true
}
ImagePicker.launchCamera(options,(responce)=>{
this.state.testImage.push({ uri: responce.uri });
const file ={
uri : responce.uri,
name :responce.fileName,
method: 'POST',
width : 50,
height : 50,
path : responce.path,
type : responce.type,
notification: {
enabled: true
}
}
this.setState(prevState => {
// get the previous state values for the arrays
let saveImages = prevState.saveImages;
// add the values to the arrays like before
saveImages.push(file);
// return the new state
return {
saveImages
}
});
const base64 = RNFS.writeFile(responce.path, 'base64');
return base64;
})
}
_upload=()=>{
if(this.state.connection_Status==="Online"){
const config ={
keyPrefix :aws_keyPrefix,
bucket : aws_bucketName,
region :aws_region,
accessKey:aws_accessKey,
secretKey :aws_secretKey,
successActionStatus :201
}
//store captured images in an array
this.state.saveImages.map((image) => {
RNS3.put(image,config)
.then((responce) => {
console.log(image);
});
});
if (this.state.saveImages && this.state.saveImages.length) {
Alert.alert("Successfully, uploaded");
//reset the arrays
this.setState({saveImages:''});
this.setState({testImage:''});
} else {
Alert.alert('No images captured');
}
} else {
Alert.alert('Upload failed. User is in offline');
}
}
render() {
return (
<View style={styles.Camera}>
<TouchableOpacity onPress={this.takePic.bind(this)}>
<Text>Take Picture</Text>
</TouchableOpacity>
<View style={styles.Send}>
<TouchableOpacity onPress={() => this._upload()}>
<Text>Send</Text>
</TouchableOpacity>
</View>
);
}
}
const styles = StyleSheet.create({
Camera :{
justifyContent: 'center',
alignItems: 'center',
marginTop : 20,
backgroundColor : '#48a4ff',
alignItems : 'center',
padding : 1,
borderWidth : 1,
borderColor : '#48a4ff',
},
Send :{
justifyContent: 'center',
alignItems: 'center',
marginTop : 20,
backgroundColor : '#48a4ff',
alignItems : 'center',
padding : 3,
borderWidth : 1,
borderColor : '#48a4ff',
}
});
export default SecondScreen;
我正在使用此代码对图像进行哈希处理,
const base64 = RNFS.writeFile(responce.path, 'base64');
return base64;
散列后的图片属性如下,
如何在上传之前将其转换为真实图像?
自从我努力一天以来,谁能帮助我。我没有任何文档来实现此功能。
答案 0 :(得分:0)
我已经使用react-native-fs库完成了此操作。我在客户端进行的图像哈希处理,即在服务器端进行的本机和哈希处理。(我将图像存储在Amezon s3中,然后使用python取消对这些图像进行哈希处理。)
我的图像哈希代码是
takePic = () => {
/* other sets of codes
.
.*/
const base64 = RNFS.writeFile(responce.uri, responce.data);
return base64;
}