Image not showing: NetworkError: 404 NOT FOUND

183 views
Skip to first unread message

Spokes

unread,
Oct 18, 2014, 11:07:55 AM10/18/14
to
I'm doing something pretty routine in defining a db table in a class within a file in modules, and later, attempting to display an image associated with that table. The table is defined like so:

class Image:

   
def __init__(self, db, auth_signature, session, request, response):
       
...

       
if not 't_image' in db.tables:
           
self.db.define_table('t_image',      
               
Field('f_user_id', type="reference auth_user", readable=False, writable=False,
                       
default=session.auth.user.id if session.auth else ''),
               
Field('image',type="upload",
                      requires
= (IS_EMPTY_OR(IS_IMAGE(
                      error_message
= current.T('Error...'),
                      extensions
= ('jpeg','jpg','png','bmp','gif'), maxsize = (1200, 1200))),IS_LENGTH(524288)),
                      label
= current.T('Image'), autodelete = True, uploadseparate = True),  
                     
                     
...
                     
               
self.auth_signature)

In attempting to display the image, I'm doing something like this in a non-default controller (I tried the equivalent in the default controller, and that didn't change anything):
               
def show_user():
   
...
   
from user_custom import Image
    cl__image
= Image(db = db, auth_signature = auth.signature, session = session,
           request
= request, response = response)

    row__image
= db(db.t_image.f_user_id == user_id).select('image').first()
    image_filename
= row__image['image']

    img = IMG(_src = URL('default', 'download/' + image_filename, extension = False))
   
...
   
return dict(img = img)

This produces a "NetworkError: 404 NOT FOUND" error. A blank image container appears on the screen, and examining it, the url that shows up looks reasonable, and seems to point to the appropriate file. Any ideas as to what could be going on and how to fix it? Thank you.
   

Leonel Câmara

unread,
Oct 18, 2014, 11:25:42 AM10/18/14
to web...@googlegroups.com
This can be simplified:
    cl__image = Image(db = db, auth_signature = auth.signature, session = session, 
           request 
= request, response = response)
to:
    cl__image = Image(db, auth.signature, session, request, response)

Consider using current in your module so you don't have to pass everything as an argument.
Anyway, if you change this does it work

    row = db(db.t_image.f_user_id == user_id).select(db.t_image.image).first()
    img = IMG(_src = URL('default', 'download', args=row.image))
    
return dict(img = img)


Spokes

unread,
Oct 18, 2014, 11:52:23 AM10/18/14
to web...@googlegroups.com
Consider using current in your module so you don't have to pass everything as an argument.

Awesome - thanks! I had no idea about that; was previously just using current to access current.T().


Anyway, if you change this does it work

Thanks, Leonel. The suggested changes didn't fix it, however. Looking at the source of the image which isn't showing, I'm seeing the same URL as was produced with the code I was previously using (127.0.0.1:8000/[app name]/default/download/[file name]). The same error message is still being produced.

Leonel Câmara

unread,
Oct 18, 2014, 12:01:25 PM10/18/14
to web...@googlegroups.com
I think I figured it out. The problem is that the table t_image isn't defined in the download function. Because it's only defined when you instantiate an Image.

Consider making a @staticmethod define_tables in Image that will define the table and call it in the models.

Spokes

unread,
Oct 18, 2014, 12:48:29 PM10/18/14
to

I tried the following:

def download():
   
print "\ndb.tables:", db.tables
   
print "\ndb.tables fields:", db['t_image'].fields
   
return response.download(request,db)

It does show that t_image is part of the db definition, and that all the fields that should be there are present.

Spokes

unread,
Oct 18, 2014, 2:28:54 PM10/18/14
to web...@googlegroups.com
Tried the approach of adding the table in the modules as well; it didn't produce any change in the results.

Any other possibilities for what could be going on? Could it be a windows filesystem issue (although I've got uploads with more unwieldy names associated with other tables)?




On Saturday, October 18, 2014 11:01:25 AM UTC-5, Leonel Câmara wrote:
Reply all
Reply to author
Forward
0 new messages