Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 993541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:26:23+00:00 2026-05-16T06:26:23+00:00

I am a total beginner to programming and Django so I’d appreciate help that

  • 0

I am a total beginner to programming and Django so I’d appreciate help that beginner can get his head round!

I was following a tutorial to show how to upload images to an Amazon S3 account with the Boto library but I think it is for an older version of Django (I’m on 1.1.2 and Python 2.65) and something has changed. I get an error:
Exception Type: TypeError
Exception Value: ‘InMemoryUploadedFile’ object is unsubscriptable

My code is:

Models.py:

from django.db import models
from django.contrib.auth.models import User
from django import forms
from datetime import datetime

class PhotoUrl(models.Model):
    url = models.CharField(max_length=128)
    uploaded = models.DateTimeField()
    def save(self):
        self.uploaded = datetime.now()
        models.Model.save(self)

views.py:

import mimetypes
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
from django.core.urlresolvers import reverse
from django import forms
from django.conf import settings
from boto.s3.connection import S3Connection
from boto.s3.key import Key

def awsdemo(request):   
def store_in_s3(filename, content):
    conn = S3Connection(settings.AWS_ACCESS_KEY_ID, settings.AWS_SECRET_ACCESS_KEY)
    b = conn.create_bucket('almacmillan-hark')
    mime = mimetypes.guess_type(filename)[0]
    k = Key(b)
    k.key = filename
    k.set_metadata("Content-Type", mime)
    k.set_contents_from_strong(content)
    k.set_acl("public-read")

photos = PhotoUrl.objects.all().order_by("-uploaded")
if not request.method == "POST":
    f = UploadForm()
    return render_to_response('awsdemo.html', {'form':f, 'photos':photos})

f = UploadForm(request.POST, request.FILES)
if not f.is_valid():
    return render_to_response('awsdemo.html', {'form':f, 'photos':photos})

file = request.FILES['file']
filename = file.name
content = file['content']
store_in_s3(filename, content)
p = PhotoUrl(url="http://almacmillan-hark.s3.amazonaws.com/" + filename)
p.save()
photos = PhotoUrl.objects.all().order_by("-uploaded")   
return render_to_response('awsdemo.html', {'form':f, 'photos':photos})

urls.py:

(r'^awsdemo/$', 'harkproject.s3app.views.awsdemo'), 

awsdemo.html:

<div class="form">
    <strong>{{form.file.label}}</strong>
    <form method="POST" action ="." enctype="multipart/form-data">
        {{form.file}}<br/>
        <input type="submit" value="Upload">
    </form> 
</div>  

I’d really appreciate help. I hope I have provided enough code.

Kind regards
AL

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T06:26:24+00:00Added an answer on May 16, 2026 at 6:26 am

    I think your problem is this line:

    content = file['content']
    

    From the Django docs:

    Each value in FILES is an UploadedFile object containing the following attributes:

    • read(num_bytes=None) — Read a number of bytes from the file.
    • name — The name of the uploaded file.
    • size — The size, in bytes, of the uploaded file.
    • chunks(chunk_size=None) — A generator that yields sequential chunks of data.

    Try this instead:

    content = file.read()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.