Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
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:

View:

def submitpicture(request):

    fuser = request.session["login"]

    copied_data = request.POST.copy()

    copied_data.update(request.FILES)

    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)

Template:

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

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

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

</form>

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

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

#MultiValueDictKeyError

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

...