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

  • SEARCH
  • Home
  • 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 6164835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:03:42+00:00 2026-05-23T22:03:42+00:00

Firstly – sorry for my English.. I’ve inherited a rather big project which uses

  • 0

Firstly – sorry for my English..
I’ve inherited a rather big project which uses ExtJS and is based on Django.. So I have an upload form and it works ok. The path to the file is given in a fileuploadfield (this is the xtype of ExtJS field) then it is taken by the Django and saved to the DB (it’s being transformed to a needed view to be stored in the base, but that’s not the problem..)
So I have smth like this:

class image(entity):
    ...

    def create(self,request):
    if request.method == 'POST':
        form = UploadFileForm(request.POST, request.FILES)
        try:
            parent_id = int(request.POST["parent_id"])
        except:
            return ErrorResponse()
        if form.is_valid():
            fl =  request.FILES['file'];
            file = fl.read()
            Obj = self.data.obj
            New = Obj()

            setattr(New,'is_main',False)

and so on..
So I need to make a file upload from a direct link. Of course by another field. Having the file from a link is not a problem (urllib2 helps great), saving the file to the media folder isn’t a problem too. But I can’t insert it in the code above. As I understand – my problem is that the file object differs from the request.FILES thing.. But I don’t know how to convert a normal file (in my case all the files are images) to the type of request.FILES so it would be readable for the next functions.. What I mean:
I catch the link to the file from another field(textfield):

            url = request.POST['link'] #It get's the user posted link
            name = urllib2.urlopen(url).read()
            f = open('media/images/picture.gif', 'wb') #I overwrite it on a dummy, couse it must be than transfered to the db
            f.write(name)
            f.close #the file can be seen in the media path

Ok. The file is now in the /media/ folder, but if I simply try to replace the
file = fl.read() with file=f.read() it doesn’t work. As I understand – the request.FILES and just a file are different.. Can anybody help me to convert my file to the needed type? Or tell me how can this idea be done.. The project is really big and if I try changing the submitting mechanism it may cause a lot of problems..
Again sorry for my English)

  • 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-23T22:03:42+00:00Added an answer on May 23, 2026 at 10:03 pm

    I really don’t understand why it didn’t work, but I found out that this works for me..

                url = request.POST['file_link']
                name = urllib2.urlopen(url).read()
                file = name
                ..
    

    the urllib2.urlopen(“link to a file”) returns a normal File and that is it..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Firstly, sorry for my flawed english and being dumb :O I just want to
Firstly, I'm using Django. Django provides gzip middleware which works just fine. Nginx also
Firstly, sorry for my English. I'm Brazilian guy that is improving yet. I want
Firstly I asked sorry if this is a stupid question. but I have a
Firstly, let me set out what I'd like to do. Assume I have three
Firstly, Real World Haskell , which I am reading, says to never use foldl
Firstly, here's my script: #!/usr/bin/python import sys, os sys.path.append('/home/username/python') sys.path.append(/home/username/python/flup) sys.path.append(/home/username/python/django) # more path
Firstly: I am totally a newbie for this kind of work. I have a
Firstly, I do not have any malicious intent out of this question. I would
Firstly, I want to apologize for my English, not my strongest side. To the

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.