I am trying to use flask to upload from a client PC to my pythonanywhere server. I'm not getting an error code so not sure where I'm going wrong.
So from the client I want to upload 2 images catt and catt2
import requests
test_files = [('cat1', open("catt.jpg", "rb")),
('cat2', open("catt2.jpg", "rb"))]
response = requests.post("http://jamesb67.eu.pythonanywhere.com/upload", files = test_files)
Then on the server side I have
app = Flask(__name__)
UPLOAD_FOLDER = '/home/Jamesb67/mysite/uploads'
ALLOWED_EXTENSIONS = {'txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'}
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
@app.route("/upload", methods=["POST"])
def upload():
uploaded_files = flask.request.files.getlist("files")
print(uploaded_files)
for file in uploaded_files:
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
return "File saved successfully"
I get a status code 200 when I check it and there is no error on my end. I have a folder called "uploads" on the website that I would expect the files to be saved to. But the code runs without an error and I'm not sure where I've went wrong?
Also is this the best way to go about things? Ideally I don't actually want to save the files I'd prefer to keep them as a variable that can be used for processing later.