0

I am trying to upload an image to the SQLite database in a blob format. I run in to the problem when I am trying to get an absolute path to the image. The error I am getting is FileNotFoundError: [Errno 2] No such file or directory: '/home/ubuntu/environment/finance/IMG_7528.JPG' I understand that it is looking for the image in my directory but I want it to be getting the image from the path on my computer, for example C:\Users\bob\Pictures\holidays.

Below is my code to get the path but the path is still showing the above error

def convertToBinaryData(filename):
#Convert digital data to binary format
my_path = os.path.abspath(os.path.dirname(__file__))
path = os.path.join(my_path, filename)
with open(path, 'rb') as file:
    blobData = file.read()
return blobData

Is there a way to get the absolute path of an image that I am trying to upload from my desktop into Cloud9 IDE?

1

To upload the image from your computer to the IDE, click on the File tab (top left), and choose Upload.

5
  • Thanks but for the final project it wouldn’t work would it? If I submit it my project and someone tests it with any other image it will throw an error. Is it possible to upload to Cloud9 from a user’s PC? – SozDaneron May 29 '20 at 22:10
  • Make sure it's stored under the document root, perhaps in the static directory. – DinoCoderSaurus May 29 '20 at 22:19
  • What do you mean by "make sure it's stored under the document root"? You mean that is where I should be storing the imagine? I am having trouble with finding the code to upload a photo from my pc to my database in a blob type, to be more specific. – SozDaneron May 30 '20 at 14:48
  • Obviously I don't understand the goal or the problem. The answer to this question "Is there a way to get the absolute path of an image that I am trying to upload from my desktop into Cloud9 IDE?" is no AFAIK. – DinoCoderSaurus May 30 '20 at 15:43
  • Ok, well that was my question. So your first answer is correct then. Thank you. – SozDaneron May 30 '20 at 15:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .