Reputation: 3
For my forum, I tried uploading a file with html using:
<form action="profiles.py" method="post">
<label class="labelOne" for="pics">Change your Profile pic </label>
<input type="file" name="uploadField" />
My python function takes that file, creates a file under userprofiles, and writes the data to it:
file = open('../data/accounts/userprofiles/'+str(form['name'].value)+'/'+'profilepics', 'w+')
file.write(str(form.getvalue('uploadField')))
file.close()
So, If I want burger.jpg
to be my picture, I upload it, python takes that and creates a file with that name burger.jpg
using w+
and then it writes the data to it(which should be the image).
However for some reason, I get no image.
What should I try next?
Upvotes: 0
Views: 1442
Reputation: 97672
Set the enctype
of your form to multipart/form-data
<form action="profiles.py" method="post" enctype="multipart/form-data">
Upvotes: 3