Explore Courses Blog Tutorials Interview Questions
0 votes
in AWS by (19.1k points)

I'm looking for a way to upload a file to s3. I am using Django. I am currently using amazon's python library for uploading along with the following code:


def submitpicture(request):

    fuser = request.session["login"]

    copied_data = request.POST.copy()


    content_type = copied_data['file'].get('content-type')

    ffile = copied_data['file']['content']

    key = '%s-%s' % (fuser, ''.join(copied_data['file']['filename'].split(' ')))

    site_s3.save_s3_data(key, ffile, content_type)


<form action="/submitpicture/" method="POST">

    <input type="file" id="file" name="file" />

    <input type="submit" value="submit" />


However, when I actually try to run it I get the following error:

"Key 'file' not found in <QueryDict: {}>"


I really don't see what I'm doing wrong. Can someone point me in the right direction?

1 Answer

0 votes
by (44.4k points)

Your <form> tag should be like this:

<form action="/submitpicture/" method="POST" enctype="multipart/form-data" >

The request.FILES will be empty without an enctype

Related questions

0 votes
1 answer

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer

Browse Categories