Setting a Limit to the Maximum Size of an Upload
Hello, I'm designing a small "briefcase" program that will allow me to quickly upload, download, and delete files in a briefcase. The only real things that I have left to do are to design a method for checking if the file exists, preventing it from overwriting files from other directories, and setting a user-configurable maximum limit on the file's size. The former two, I can handle by myself with no problem. However, the I'm having a little trouble with. thefile = params["upfile.file"] if os.path.getsize(thefile) <= conf["upmax"]: print "File Size Okay." #Add Functions Later... else: print "File Too Large." #Here, too. CGItb reported the following error: TypeError: coercing to Unicode: need string or buffer, instance found args = ('coercing to Unicode: need string or buffer, instance found',) This seems like an incredibly simple problem, but I just can't seem to wrap my mind around it. Thank you for your help. -- http://mail.python.org/mailman/listinfo/python-list
Re: Setting a Limit to the Maximum Size of an Upload
Here is a basic overview of the variables included there. params = cgi.FieldStorage() I accidentally made a mistake when typing what the "thefile" variable is. thefile = params["upfile"].file "upfile" is the CGI field that contains the file that I'm uploading. As you can see, the if statement just compares two values, os.path.getsize(thefile) and conf["upmax"], a variable I set that is designated as the maximum file size allowed. I'm assuming that this is all the information you need. I'm sorry for not including it earlier; I was in a bit of a rush. ^.^ -- http://mail.python.org/mailman/listinfo/python-list
Re: Setting a Limit to the Maximum Size of an Upload
I'm afraid on my interpreter, this works. >>> if os.path.getsize("C:\\Documents and Settings\\Joey\\Desktop\\file.txt") >>> <= 1000: >>> print "<= 1000." <= 1000. No problems there, as you can see. -- http://mail.python.org/mailman/listinfo/python-list
Re: Setting a Limit to the Maximum Size of an Upload
Oh, I'm sorry, I didn't understand what you meant at first. Then I read your reply over again and noticed that you said that the problem lied in os.path.getsize() when I tried to run it on the contents of an open file. I'll try the method you outlined now. -- http://mail.python.org/mailman/listinfo/python-list
Re: Setting a Limit to the Maximum Size of an Upload
Yes, I see that now. I tried your method and it seemed to work fine until I tried printing the filesize out. def checkfilesize(thefile): # Check the Size of the File global filesize thefile.seek(0,2) filesize = thefile.tell() thefile.seek(0) print filesize print conf["upmax"] if filesize <= conf["upmax"]: print "File Size Okay." noupload = False else: print "File is too Large." noupload = True Basically conf["upmax"] is a number that I extract from a configuration file that is the maximum size of an upload. I had tried setting conf["upmax"] to 1 and it should have technically disallowed a 28 byte file to pass through. But it did, so I added two lines to print the file size and the conf["upmax"] variable. The file size turned out to be "0"! thefile still is just params["upfile"].file, by the way. Any suggestions? -- http://mail.python.org/mailman/listinfo/python-list
Using win32ui.CreateFileDialog() to get the name of a file.
Hello. I'm writing a program that creates a series of batch operations to convert movies to be used on iPodLinux. The programs that do the encoding and conversions are seperate from mine and all mine does is use os.system() to call the program. However, it needs to get an input file and an output file. Originally I was using just raw input, but I got adventuresome and decided to try win32ui.CreateFileDialog(). But this will only open or save a file and its output will be either 1 or a failure. How might I go about using it to get the _file name_ of a file. For example. Box appears asking user to find a file they want. They double click on the file. Let's call it C:\Video.avi Then another dialog box appears asking them where to save it. They save it at C:\iPodVideo.avi. Now the Python program extracts the name of these files and then uses os.system() to run: mencoder.exe -[parameters] C:\Video.avi -o C:\iPodVideo.avi Note that I'm not actually inputting the contents of the file, I'm just passing the file name along. How might I do this? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Using win32ui.CreateFileDialog() to get the name of a file.
Okay, thank you. This worked very well. -- http://mail.python.org/mailman/listinfo/python-list
Re: Super Newbie Question
To reply to many of your messages (I'm using Google right now due to lack of a better newsreader at the moment), the issue with the temporary file is that when I write something new to it, if the old contents of the file was larger, not all of it will be overwritten. So, the truncate() method will work very well. Thank you Mr. Neuhauser, Mr. Ewing, and all others. -- http://mail.python.org/mailman/listinfo/python-list
Re: Best editor?
When I'm using Windows, I have found the Syn TextEditor (http://syn.sourceforge.net) to be quite useful. It has basic syntax highlighting, about enough for me and is quite compatible with FTP and such. It supports Python pretty well. Its user interface is quite easy yet pretty powerful. All in all, this is a very good editor, good enough that I probably won't go looking for another one any time soon. On Linux however (which I haven't used in quite some time, sadly), I usually use vim more than emacs. To tell you the truth, I haven't really used emacs that much at all, only for a short time. I keep meaning to actually try it out and get used to it, but I always find that if I need to edit a file quickly, I just go to vim. Then again, I don't write much Python code in Linux anyways. Even so, I intend to try emacs out soon. -- http://mail.python.org/mailman/listinfo/python-list
Stupid Newbie Question Concerning CGI and Reading Forward Slashes
Hi, I want to make a configuration script for something and it needs to read inputs from an HTML file. A couple of these inputs are textboxes that the user inputs a path in. For example: Your Home Directory: [/home/me/public_html/] So, I'm using Python to read these inputs and store them in a configuration file. However, I cannot get the CGI to read the forward slashes (/). It just leaves a blank area. So, for example: Input: /usr/bin/sendmail Reads: sendmail Input: /home/me/public_html/ Reads: (Nothing.) params = cgi.FieldStorage() def writep(key, name): if params.has_key(key): fconfig.write(name + ": " + os.path.split(params[key].value)[1] + ";\n") ^ This is the function for handling a key that is read by the cgi. The "name" is the name that it stores the key under so the configuration file looks like: name: key;[Line Break] However, is there a way to get it to read the forward slashes? If there isn't do you suggest having the user use a different character and adding a function in the script to substitute a forward slash for that character? I tried looking for this for a long while, but maybe I didn't search enough. Thanks for all of your help and I'm sorry if this is a question that has been asked 15 million times. Joey C. -- http://mail.python.org/mailman/listinfo/python-list
Re: Stupid Newbie Question Concerning CGI and Reading Forward Slashes
Steve Holden wrote: > It's not a common question, but it's relatively easily answered. You are > splitting everything but the filename off with os.path.split and then > complaining about the result! Once you stop doing that your problem is > solved. Thus, it's a stupid newbie question. Thanks a lot for your help. It seems I was just being plain stupid. -- http://mail.python.org/mailman/listinfo/python-list