I'm new to Google app engine with python ,please help me!
Here is my html code:
<form action="" method="POST">
<div class="form-group">
<label for="uploaded_file">Attached file:</label>
<input type="file" id="uploaded_file" name="uploaded_file">
</div>
<div class="form-group">
<button class="btn-primary" type="submit">Save note</button>
</div>
</form>
Here is my python code:
def post(self):
uploaded_file = self.request.POST.get('uploaded_file')
file_name = getattr(uploaded_file, 'filename', None)
file_content = getattr(uploaded_file, 'file', None)
if uploaded_file:
self.response.out.write(uploaded_file)
self.response.out.write(file_name)
self.response.out.write(file_content)
I deploy my project to Google app engine and visit the website. I choose a picture and click the submit button, it can show uploaded_file(file's name). But, file_name and file_content show None.
If I modify my code :
def post(self):
uploaded_file = self.request.POST.get('uploaded_file')
file_name = getattr(uploaded_file, 'filename')
file_content = getattr(uploaded_file, 'file')
It will show:
File "C:\Users\pc2\Desktop\test\main.py", line 98, in post
file_name = getattr(uploaded_file, 'filename')
AttributeError: 'unicode' object has no attribute 'filename'
Someone help me to get file or picture ,please!