How to use the aws-amplify.Storage.put 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 dabit3 / appsync-image-rekognition / src / App.js View on Github external
saveImageFromCanvas = () => {
    this.setState({ processing: true })
    var image = new Image()
    image.id = "pic" + getRandomInt()
    var canvas = document.getElementById("canvas");
    image.src = canvas.toDataURL();

    var blobBin = atob(image.src.split(',')[1]);
    var array = [];
    for(var i = 0; i < blobBin.length; i++) {
        array.push(blobBin.charCodeAt(i));
    }
    var file = new Blob([new Uint8Array(array)], {type: 'image/png'});

    const fileName = getRandomInt() + 'user_picture.png'
    Storage.put(fileName, file)
      .then(res => {
        const imageInfo = { imageName: fileName }
        API.graphql(graphqlOperation(Query, imageInfo))
          .then(data => {
            console.log('data:', data)
            const parsedData = JSON.parse(data.data.process.results)
            this.setState({
              processing: false,
              rekognitionData: parsedData.FaceDetails
            })
        })
        .catch(error => {
          console.log('error: ', error)
          this.setState({
            processing: false,
          })
github AJInteractive / InterviewJS / packages / composer / src / partials / panes / interviewee / ImagePane.js View on Github external
handleBlob(blob, type, name) {
    const key = fileToKey({ type, name: sanitizeFilename(name.replace(/ /g, "_")) }, this.props.story.id);
    Storage.put(`files/${this.props.user.id}/${this.props.story.id}/${key}`, blob, {
      bucket: "data.interviewjs.io",
      level: "public",
      contentType: type,
    })
      .then(async result => {
        console.log(result);
        this.setState(
          {
            draft: {
              ...this.state.draft,
              value: `https://story.interviewjs.io/files/${this.props.user.id}/${this.props.story.id}/${key}`,
            },
          },
          () => this.props.updateDraft(this.state.draft)
        );
      })
github aws-samples / aws-amplify-vue / src / amplify / components / storage / PhotoPicker.vue View on Github external
pick: function(e) {
      const file = e.target.files[0];
      const { name, size, type } = file;
      logger.debug(file);

      logger.debug('upload photo to ' + this.path)
      Storage.put(this.path, file, { contentType: type })
        .then(data => {
          logger.debug(data)
          this.getPhoto()
        })
        .catch(err => logger.error(err));
    },
    imageError: function(e) {
github dabit3 / appsync-image-rekognition / src / App.js View on Github external
saveFile = (labels) => {
    if (this.state.imageName === '') return
    this.setState({ processing: true })
    Storage.put(this.state.imageName, this.state.imageInfo)
    .then (result => {
      const image = {
        imageName: this.state.imageName
      }
      if (labels) {
        image.type = 'labels'
      }
      API.graphql(graphqlOperation(Query, image))
        .then(data => {
          const parsedData = JSON.parse(data.data.process.results)
          if (parsedData.FaceDetails) {
            this.setState({
              processing: false,
              rekognitionData: parsedData.FaceDetails
            })
          }
github ionic-team / starters / ionic-angular / official / aws / src / pages / account / account.ts View on Github external
uploadFromFile(event) {
    const files = event.target.files;
    logger.debug('Uploading', files)

    const file = files[0];
    const { type } = file;
    Storage.put(this.userId + '/avatar', file, { contentType: type })
      .then(() => this.refreshAvatar())
      .catch(err => logger.error(err));
  }
github aws-amplify / amplify-js / packages / aws-amplify-react-native / dist / Storage / S3Image.js View on Github external
load() {
        const { imgKey, body, contentType, level } = this.props;
        if (!imgKey) {
            logger.debug('empty imgKey');
            return;
        }

        const that = this;
        logger.debug('loading ' + imgKey + '...');
        if (body) {
            const type = contentType ? contentType : 'binary/octet-stream';
            const opt = {
                contentType: type,
                level: level ? level : 'public'
            };
            const ret = Storage.put(imgKey, body, opt);
            ret.then(data => {
                logger.debug(data);
                that.getImageSource();
            }).catch(err => logger.warn(err));
        } else {
            that.getImageSource();
        }
    }
github alanbo / serverless-cms / admin / src / components / inputs / galleries / elements / S3ImageUpload.tsx View on Github external
const storage = file_arr.map(file => {
    let options: { [opts: string]: any } = { contentType: 'image/jpeg' };

    if (gallery) {
      options.metadata = {
        gallery
      }
    }

    return Storage.put(`temp/${file.name}`, file, options);
  });
github aws-amplify / amplify-js / packages / aws-amplify-react-native / src / Storage / S3Image.js View on Github external
load() {
        const { imgKey, body, contentType, level } = this.props;
        if (!imgKey) {
            logger.debug('empty imgKey');
            return ;
        }

        const that = this;
        logger.debug('loading ' + imgKey + '...');
        if (body) {
            const type = contentType? contentType : 'binary/octet-stream';
            const opt = {
                contentType: type,
                level: level? level : 'public'
            }
            const ret = Storage.put(imgKey, body, opt);
            ret.then(data => {
                logger.debug(data);
                that.getImageSource();
            })
            .catch(err => logger.warn(err));
        } else {
            that.getImageSource();
        }
    }