Przeglądaj źródła

upload png/jpg works, working on uploading pdfs

bscheibel 4 lat temu
rodzic
commit
9771b97d89
2 zmienionych plików z 9 dodań i 4 usunięć
  1. 1 1
      app/templates/show_image.html
  2. 8 3
      app/views.py

+ 1 - 1
app/templates/show_image.html

@@ -1,7 +1,7 @@
 <!doctype html>
 <title>Hello from Flask</title>
 {% if filename %}
-  <h1>some text <img src="{{ url_for('send_file', filename=filename) }}">more text!</h1>
+  <h1>some text <embed src="{{ url_for('send_file', filename=filename) }}" type="application/pdf">more text!</h1>
 {% else %}
   <h1>no image for whatever reason</h1>
 {% endif %}

+ 8 - 3
app/views.py

@@ -1,9 +1,13 @@
 from app import app
 import os
 from flask import Flask, request, redirect, url_for, send_from_directory, render_template
-UPLOAD_FOLDER = '/Users/beatescheibel/Desktop/flask/uploads'
+from wand.image import Image as wandImage
+#https://medium.com/@emerico/convert-pdf-to-image-using-python-flask-2864fb655e01
+
+
+UPLOAD_FOLDER = '/home/bscheibel/Desktop/flask/uploads'
 app.config["UPLOAD_FOLDER"] = UPLOAD_FOLDER
-ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'])
+ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif', 'PDF'])
 
 
 @app.route("/")
@@ -22,7 +26,8 @@ def upload_file():
         if file and allowed_file(file.filename):
 
             filename = file.filename
-            file.save(os.path.join(app.config["UPLOAD_FOLDER"], filename))
+            image = wandImage(filename=filename)
+            image.save(os.path.join(app.config["UPLOAD_FOLDER"], filename))
             return redirect(url_for('uploaded_file', filename=filename))
     return '''
     <!doctype html>