Do I have to do something like db.define_table('image', Field('url','string'), Field('image_file','blob'), Field('image_upload','upload',uploadfield= Field('image_file','blob'))
Where i provided a filed in the uploadfield On Thursday, July 5, 2012 10:30:22 PM UTC-7, RCTYCO wrote: > > Thanks. > > I need to solve the problem of the file not been uploaded to the blob > field. > > I believe i am doing it correctly. > > I defined the model > db.define_table('image', > Field('url','string'), > Field('image_file','blob'), > Field('image_upload','upload',uploadfield='image_file')) > > > I stepped through the code for the store function > (db.image.image_upload.store(response,filename=url))). > > I expect line 7345 to turn out to be true to it eval to false. So my file > is never uploaded to the blob file. > File: gluon.dal > > Line 7345: if isinstance(self.uploadfield,Field): > Line 7346: blob_uploadfield_name = self.uploadfield.uploadfield > Line 7347: keys={self.uploadfield.name: newfilename, > Line 7348: blob_uploadfield_name: file.read()} > Line 7349: self.uploadfield.table.insert(**keys) > > > I am assuming that I am messing up my define_table. Or I am using the > wrong field when i call the store function. > > > > On Thursday, July 5, 2012 7:36:39 PM UTC-7, Massimo Di Pierro wrote: >> >> I did not know you were storing it in a blob. Try: >> >> >> def getImage(url,db): >> user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)' >> headers = {'User-Agent': user_agent} >> >> req = urllib2.Request(url,"",headers) >> >> try: >> response = urllib2.urlopen(req) >> except urllib2.URLError, e: >> if hasattr(e, 'reason'): >> print 'We failed to reach a server.' >> print 'Reason: ', e.reason >> elif hasattr(e, 'code'): >> print 'The server couldn\'t fulfill the request.' >> print 'Error code: ', e.code >> id = >> db.image.insert(url=url,image_uplaod=db.image.image_upload.store(response,filename=url)) >> db.commit() # not sure if needed, depends on where executed >> return id >> >> def imageLookup(): >> id = request.vars.id >> response.headers['Content-Type']='image/jpeg' >> return db.image[id].image_file >> >> On Thursday, 5 July 2012 14:16:55 UTC-5, RCTYCO wrote: >>> >>> Thank you for the quick response. >>> >>> I added the lines above : ( id = >>> db.image.insert(url=url,image=db.image.image_upload.store(response,filename=url)) >>> db.commit() ) >>> >>> It uploaded the information (url and renamed the file) but I don't >>> believe it upload the image to the database. >>> >>> This is what it uploaded. Image_file is empty. >>> id,url,image_upload,image_file >>> '1', 'http://eandata.com/image/products/000/000/015/0000000151122.jpg', >>> 'image.image_upload.94df8d0ebb1047e0.303030303030303135313132322e6a7067.jpg', >>> >>> <Null> >>> >>> This is my model. >>> Model >>> db.define_table('image', >>> Field('url','string'), >>> Field('image_upload','upload',uploadfield='image_file'), >>> Field('image_file','blob')) >>> >>> Any suggestions? >>> >>