First of all Your form needs to have its enctype="multipart/form-data"
In your function for page in your controller you'll have a paramter with the same name as the name of the file input tag on your form. That parameter is an object with .file and .filename You could have something like this in your code def upload(self, file=None) fd = open(file.filename, 'w') shutil.copyfileobj(file.file, fd) fd.close() The .file object is a standard Python file like object and can be used like that On Feb 7, 12:18 pm, "Fabian" <[EMAIL PROTECTED]> wrote: > Hello, > I've had nothing but problems getting this to work so i'll just > describe what i want to do and maybe someone here could help me out: > > 1) Get images uploaded via the method describe in the upload with > progressbar tutorial in the rough-docs > 2) write image into a StringIO or similar > 3) write a copy into the database > 4) make a thumbnail via PIL > 5) save thumbnail into database > > Now so far i've been getting nothing but errors so i think i've been > on the wrong track. Could someone just quickly list what objects to > use in this process is StringIO the way to go? The code is here below. > imageObject is just an Int. I've been getting decoding errors about > character not being in ascii range which i assume is because it tries > to decode the stringIO object, how do i tell it that it contains > binary data? > > Thanks a lot > Fabian > > def save_file(self, filepath, file, imageObject): > """ Safely save a file to the location given by filepath """ > chunk_size = 8192 > # return if file is empty > if not file: > return > #read file that is being uploaded into a memory file > # create new file on file system > savedfile = StringIO.StringIO() > # save data to this new file in chunks > while True: > data = file.read(chunk_size) > if not data: > break > savedfile.write(data) > > savedfile.seek(0) > > #create thumbnail > tempThumb = Image.open(savedfile) > tempThumb = tempThumb.resize((128, 128)) > fileOut = StringIO.StringIO() > fileOut.seek(0) > savedfile.seek(0) > tempThumb.save(fileOut, 'PNG') > > # create file entry in database > newImage = image(imageName = None, > imageDescription = None, > imagePoints = None, > imageComplete = False, > imageMap = False, > imageMapPoint = False, > imageFile = savedfile.getvalue(), > imageThumb = None, > imageObject = int(imageObject), > imageSpace = None, > imageFormat = 1) > return --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "TurboGears" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/turbogears?hl=en -~----------~----~----~----~------~----~------~--~---

