title: Sending directory to client from server flask
body: <p>I am trying to return a directory of images from the server to the client. I'm having a hard time understanding how to format my response so that the client is able to distinguish between the files.</p>
  
  <p>What is the best practice way to accomplish what I am doing? my photos are kept in a tmp folder within the application. Here is my utils.py:</p>
  
  <pre><code>def get_multipart_fields():
      final = {}
      for file in os.listdir(os.path.dirname(os.path.realpath(__file__)) + '/tmp'):
          try:
              with open(os.path.dirname(os.path.abspath(__file__)) + '/tmp/' + os.path.join(file), "rb") as image_file:
                  encoded_string = base64.b64encode(image_file.read())
                  final[os.path.join(file)] = { 'filename': encoded_string }
  
          except Exception as e:
              print e
  
      return final.to_string()
  </code></pre>
  
  <p>and my views.py:</p>
  
  <pre><code>@app.route('/download-files', methods=['GET'])
  def gallery():
      client = get_client()
      resource = get_resource()
      download_dir(client, resource, 'test-bucket')
  
      file_names = get_multipart_fields()
  
      m = MultipartEncoder(
          fields=file_names
      )
  
      return Response(json.dumps(m), mimetype=m.content_type)
  </code></pre>
  
  <p>Where am I going wrong with this logic ? Any help would be greatly appreciated. </p>