I am attempting to write a function that will eventually go in to a migration script to upload legacy data files. As you can see I use the DAL and define the wiki_media table. The function below looks just like the example in the book.<http://web2py.com/books/default/chapter/29/06?search=programmatically>However when I run it from the command line I get an error that the _attempt_upload(fields) method cannot handle the upload. See below.
Doe anyone know of a way to insert files into the database with a script? I am using an upload field instead of upload directory. Also using a recent trunk version of web2py. import os, sys from gluon import DAL, Field from easygui import fileopenbox, diropenbox db = DAL('oracle://...', auto_import=True) db.define_table('wiki_media', Field('wiki_page', 'reference wiki_page'), Field('title', required=True), Field('filename', 'upload', required=True), Field("filedata", "blob"), migrate=False) db.wiki_media.filename.uploadfield='filedata' file_id = None def upload_file(): """demonstrate uploading a file programmatically, """ stream=None file_path=fileopenbox(msg='Pick a file', title='Choose file', default=None) if file_path: print 'file_path= '.join([file_path]) stream = open(file_path, 'rb') else: return None file_id=db.wiki_media.insert(filename=db.wiki_media.filename.store(stream,file_path), filedata=stream.read()) stream.close() return file_id Error: Microsoft Windows [Version 6.1.7600] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\Users\bthayer>cd %WEB2PY_HOME% C:\web2py-1045bab06391\web2py-1045bab06391>cd appl*/TAMOTO C:\web2py-1045bab06391\web2py-1045bab06391\applications\TAMOTO>cd private C:\web2py-1045bab06391\web2py-1045bab06391\applications\TAMOTO\private>python Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import test_tamoto_rpc as trpc >>> trpc.upload_file() C:\Users\bthayer\Documents\car\carfiles.txt Traceback (most recent call last): File "<stdin>", line 1, in <module> File "test_tamoto_rpc.py", line 33, in upload_file filedata=stream.read()) File "C:\web2py-1045bab06391\web2py-1045bab06391\gluon\dal.py", line 8276, in insert self._attempt_upload(fields) File "C:\web2py-1045bab06391\web2py-1045bab06391\gluon\dal.py", line 8258, in _attempt_upload raise RuntimeError("Unable to handle upload") RuntimeError: Unable to handle upload >>> Thanks for your time. -Bill -- --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.