0

Good day to all!

So, I have been trying to put an upload function on my python-flask application. It does scan the picture for backdoors, malicious files, etc etc and then checks if it is an image using imghdr.what() which works perfectly until i used file.stream.read method. this method can only read the stream once. after you read it. it returns ' ' or empty. below are the screenshots.

This is the debugger output:

This is the debugger output

This is my code:

This is my code

And this is the files that it saved. all 0 byte:

And this is the files that it saved. all 0 byte

If i remove the partthat scans for malicious codes on the image ( the part where i used file.stream.read() ) the upload function works fine. Thankyou in advance :)

Skrmnghrd
  • 558
  • 4
  • 10

1 Answers1

1

It seems that the file.stream.read() puts the cursor at the end of the filestream so, you need to do file.seek(0) to return the cursor back to the beginning of the filestream answer was found here Why can't I call read() twice on an open file?

Skrmnghrd
  • 558
  • 4
  • 10