Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

S3 Exception #1

Open
AmoDinho opened this issue Jun 17, 2019 · 2 comments
Open

S3 Exception #1

AmoDinho opened this issue Jun 17, 2019 · 2 comments

Comments

@AmoDinho
Copy link
Collaborator

""InvalidS3ObjectException: Unable to get object metadata from S3. Check object key, region and/or access permissions.\n

@AmoDinho
Copy link
Collaborator Author

AmoDinho commented Jun 23, 2019

const AWS = require('aws-sdk')
AWS.config.update({region: 'us-east-1'})
var rekognition = new AWS.Rekognition()
const fs = require('fs');



exports.handler = (event, context, callback) => {
 
 
 const toDataURL = url => fetch(url)
     .then(response => response.blob())
     .then(blob => new Promise((resolve, reject) => {
      const reader = new FileReader()
      reader.onloadend = () => resolve(reader.result)
      reader.onerror = reject 
      reader.readAsDataURL(blob)
     }))

 
const image = toDataURL(event.imageInfo)
   .then(dataURL => {
    dataURL;
   })

 var params = {
     Image: {
        Bytes: image
        /* S3Object: {
             Bucket: "pmb-traimages",
             Name:  "/" + event.imageInfo,
             Version: "Latest Version"
             
         }*/
     }
 }; 
 
 
  rekognition.detectText(params, function(err, data){
     if(err){
         callback(null, {
             data: JSON.stringify(err.stack)
         })
     } else {
         const myData = JSON.stringify(data)
         callback(null, {
             data: myData
         })
     }
 })
 
 
 

};


/*
How would you use axios with/or node fetch library 

and convert oall of the code to es6?


//A Func that reads the url of the s3 bucket
async readS3() => {
 return new Promise((resolve, reject) => {
  
  const Options = {
   path: event.info,
   method: 'PUT'
  };
  
  const req = http.request(options, (res) => {
    resolve('Success')
  });
  
  req.on('error', (e) => {
    reject(e.message)
  });
  
  req.write('');
  req.end();
  });
 };
 
 
 //create a variable that holds the blob of the image
 const imageBlob = readS3()
 .then(response => response.blob())
     .then(blob => new Promise((resolve, reject) => {
      const reader = new FileReader()
      reader.onloadend = () => resolve(reader.result)
      reader.onerror = reject 
      reader.readAsDataURL(blob)
     }))
 
 
 //create the rekognition blob
 
 var params = {
     Image: {
        Bytes: imageBlob
       
     }
 }; 
 
 
 //call rekognition and return it
  rekognition.detectText(params, (data, err) => {
  
  try {
  const rekData = JSON.stringyfy(data)
   return rekData
  
   
  } catch (err){
   return err.message
  }
   
  })
  
  
  


*/


@AmoDinho
Copy link
Collaborator Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant