IBM Cloud Watson Visual Recognition image classification.. Error in uploading file

142 Views Asked by At

Through my IBM Cloud account, I have registered a Watson Visual Recognition service. Then I tried using their API to upload an image 'fruitbowl.jpg' to my bucket associated with this service and then get some analysis on that image.

I have tried the code available at link

Till the API and bucket validation, code works fine but throws error

"`FileNotFoundError: [Errno 2] No such file or directory: 'fruitbowl.jpg'" at: 

cos.upload_file(Filename='fruitbowl.jpg',Bucket=credentials['BUCKET'],Key='fruitbowl.jpg')

I can see that this file is available in my bucket.

Code:

from ibm_botocore.client import Config
    import ibm_boto3
    def download_file_cos( credentials, local_file_name, key ):
        cos = ibm_boto3.client( service_name            = 's3',
                                ibm_api_key_id          = credentials['IBM_API_KEY_ID'],
                                ibm_service_instance_id = credentials['IAM_SERVICE_ID'],
                                ibm_auth_endpoint       = credentials['IBM_AUTH_ENDPOINT'],
                                config=Config(signature_version = 'oauth'),
                                endpoint_url            = credentials['ENDPOINT'] )
        try:
            cos.upload_file( Filename='fruitbowl.jpg',Bucket=credentials['BUCKET'],Key='fruitbowl.jpg')
        except Exception as e:
            print( Exception, e )
        else:
            print( 'File Downloaded' ) 

My current directory for IBM cloud notebook is

0

There are 0 best solutions below