How to use the aws-amplify.Storage.get function in aws-amplify

To help you get started, we’ve selected a few aws-amplify examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github AJInteractive / InterviewJS / packages / composer / src / actions / actionCreators.js View on Github external
stories.forEach(({ key }) => {
          Storage.get(key, {
            bucket: "data.interviewjs.io",
            level: "private"
          })
            .then((url) => {
              axios
                .get(url)
                .then((response) => {
                  // console.log('AWS', response.data);
                  if (response.data.ignore) {
                    dispatch(noop());
                  } else {
                    dispatch(syncStory(response.data));
                  }
                })
                .catch((error) => Raven.captureException(error));
            })
github aws-samples / aws-mobile-react-native-starter / client / src / Screens / Home.js View on Github external
return Promise.all(apiResponse.map(async (pet) => {
        // Make "key" work with paths like:
        // "private/us-east-1:7817b8c7-2a90-4735-90d4-9356d7f8f0c7/091357f0-f0bc-11e7-a6a2-937d1d45b80e.jpeg"
        // and
        // "44b223e0-9707-11e7-a7d2-cdc5b84df56b.jpeg"
        const [, , , key] = /(([^\/]+\/){2})?(.+)$/.exec(pet.picKey);

        const picUrl = pet.picKey && await Storage.get(key, { level: 'private' });

        return { ...pet, picUrl };
      }));
    }).then(apiResponse => {
github aws-samples / aws-appsync-chat-starter-react / src / components / Message.js View on Github external
const { file } = this.props.msg
    if (file && file.key) {
      const fileUrl = Cache.getItem(file.key)
      if (fileUrl) {
        console.log(`Retrieved cache url for ${file.key}: ${fileUrl}`)
        this.setState({ key: file.key })
        return this.setState({ fileUrl })
      }

      const [, identityIdWithSlash, keyWithoutPrefix] =
        /([^/]+\/){2}(.*)$/.exec(file.key) || file.key
      const identityId = identityIdWithSlash.replace(/\//g, '')
      console.log(
        `Retrieved new key for ${file.key}: ${identityId} - ${keyWithoutPrefix}`
      )
      Storage.get(keyWithoutPrefix, { identityId }).then(fileUrl => {
        console.log(`New url for ${file.key}: ${fileUrl}`)
        const expires = moment()
          .add(14, 'm')
          .toDate()
          .getTime()
        Cache.setItem(file.key, fileUrl, { expires })
        this.setState({ fileUrl })
      })
    }
  }
github jamstack-cms / jamstack-cms / src / components / editpost.js View on Github external
async componentDidMount() {
    const { id } = this.props
    let wildcard = this.props["*"]    
    if (wildcard === 'edit') {
      this.setState({ isEditing: true })
    }
    try {
      let authorAvatar
      const postData = await API.graphql(graphqlOperation(getPost, { id }))
      console.log('postData: ', postData)
      const { getPost: post } = postData.data
      if (post.author.avatarUrl) {
        authorAvatar = await Storage.get(post.author.avatarUrl)
      }
      if (wildcard !== 'edit') {
        const updatedContent = await getSignedUrls(post.content)
        post['content'] = updatedContent
      }
      if (post['cover_image']) {
        const coverImage = await Storage.get(getKeyWithPath(post['cover_image']))
        post['cover_image'] = coverImage
      }
      this.setState({
        authorName: post.author.username,
        post, isLoading: false,
        authorAvatar: authorAvatar ? authorAvatar : null })
    } catch (err) { console.log({ err })}
  }
  setPost = (key, value) => {
github awslabs / media-analysis-solution / source / web_site / src / components / result.js View on Github external
.then(function(response) {

        var filepath = ['media',response.object_id,'content',response.details.filename].join('/');
        Storage.get(filepath,{level: 'private'})
        .then(function(file) {
          self.setState({
            downloading: false,
            media_file: file,
            error_status: false
          })
        })
        .catch(function(err) {
          //console.log(err);
        });

        self.setState({
            filename: response.details.filename,
            file_type: response.details.file_type
        });
github jamstack-cms / jamstack-cms / src / pages / profile.js View on Github external
setAvatar = async () => {
    const { imageFile, sub } = this.state
    const { setAvatar } = this.props.context
    const key = `images/avatars/${sub}.jpg`
    try {
      await Storage.put(key, imageFile)
      const signedImage = await Storage.get(key)
      setAvatar(signedImage)
      const updatedUserInfo = { id: sub, avatarUrl: key }
      await API.graphql(graphqlOperation(updateUser, { input: updatedUserInfo }))
      console.log('updated user info...')
    } catch (err) {
      console.log('error setting avatar... :', err)
    }
  }
  render() {
github dabit3 / appsync-web-translator / src / App.js View on Github external
translate = async () => {
    if (this.state.text === '') return
    this.setState({ fetching: true, audioReady: false })
    const code = codes[this.state.language].code

    const data = {
      code,
      sentence: this.state.text
    }
    console.log('data: ', data)
    try {
      const audioData = await API.graphql(graphqlOperation(GetAudioQuery, data))
      const key = audioData.data.getTranslatedSentence.sentence
      const url = await Storage.get(key);
      console.log('The URL is', url);
      this.audio = new Audio(url)
      this.setState({
        audioReady: true,
        fetching: false
      })
    } catch (err) {
      console.log('error hitting graphql: ', err)
    }
  }
github aws-samples / aws-amplify-vue / src / amplify / components / storage / PhotoPicker.vue View on Github external
getPhoto: function() {
      Storage.get(this.path)
        .then(url => this.src = url)
    },
    pick: function(e) {
github odyssy-automaton / pocket-moloch / src / utils / ProposalService.js View on Github external
export const GetMetaData = async (id) => {
  const uri = await Storage.get(`proposal_${id}.json`);

  try {
    const res = await fetch(uri);
    if (!res.ok) {
      throw new Error(res.statusText);
    }
    return res.json();
  } catch (err) {
    return { error: err };
  }
};
github jamstack-cms / jamstack-cms / src / components / pageTemplates / heroTemplate.js View on Github external
baseComponents = await Promise.all(baseComponents.map(async component => {
          if (component.type === 'image') {
            if (
              (!component.content.imageHtml.includes('blob:http')) &&
              (!component.content.imageHtml.includes('&X-Amz-SignedHeaders=host'))
            ) {              
              const imageSource = getImageSource(component.content.imageHtml)
              const key = getKeyWithPath(imageSource)
              const signedImage = await Storage.get(key)
              component.content.imageHtml = `<img src="${signedImage}">`
            }
          }
          return component
        }))