title: Converting multiple images into Base64 string and and save it in folder with txt extension
body: <pre><code>import base64
  import json
  import uuid
  import os
  from os import listdir
  
  
  file_path=&quot;C:/Users/***/Documents/Projects/Falsk_API_Img2Base64/image/&quot;
  
  output_path=&quot;base64_txt_folder/&quot;
  
  Unique_ID = uuid.uuid1()
  
  def create_image_file(images):
      input_path=os.path.join(file_path, images)
      with open(input_path, &quot;rb&quot;) as image2string:
          converted_string = base64.b64encode(image2string.read()).decode('ascii')
          payload = json.dumps({&quot;imagedata&quot;: converted_string})
          file = open(output_path+'image_'+str(Unique_ID)+'.txt', 'w')
          file.write(payload)
          file.close()      
  
  for images in os.listdir(file_path):
      create_image_file(images)
  </code></pre>
  <p>I am trying to encode a set of images (100 images in folder) to base64 format and save it in text format individually in the output folder. This code is taking only one image for converting it to base64 and exiting from the loop. It is not taking the next image for conversion. The requirement is, if I run this code, it has to take one image at a time and convert it into base64 format and save that string in JSON format in a text file, and then it has to take 2nd image to conversion and save it in text format and so on till the last image in the folder.</p>
  <p><a href="https://i.stack.imgur.com/7Sovd.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7Sovd.jpg" alt="Please take a look at the image" /></a></p>