Skip to content

Instantly share code, notes, and snippets.

@alaingoldman
Created September 20, 2017 18:16
Show Gist options
  • Select an option

  • Save alaingoldman/b58a14e096eb3992f63bfca1b4d3ab93 to your computer and use it in GitHub Desktop.

Select an option

Save alaingoldman/b58a14e096eb3992f63bfca1b4d3ab93 to your computer and use it in GitHub Desktop.
import { RNS3 } from 'react-native-aws3';
// ....
stringGen(len){
// for generating random strings obviously
let text = "";
let charset = "abcdefghijklmnopqrstuvwxyz0123456789";
for( var i=0; i < len; i++ )
text += charset.charAt(Math.floor(Math.random() * charset.length));
return text;
}
addPhoto(){
let that = this;
let options = {
keyPrefix: "imgs/",
bucket: "secretbucketname",
region: "us-east-1",
accessKey: "AK----------------",
secretKey: "2X----------------------------------",
successActionStatus: 201
};
let randString1 = (this.stringGen(23)) + ".jpg";
let somePhoto = {
uri: this.state.photoLocation,
name: randString1,
type: this.state.photoType
};
RNS3.put(somePhoto, options).then(response => {
if (response.status !== 201){
alert("some error occured");
}else{
that.setState({
photoLiveLocation: response.body.postResponse.location,
})
}
}).catch(function(error){
alert(error.message);
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment