Last post Dec 05, 2007 10:10 PM by crf250guy
Nov 28, 2007 04:39 PM|fizzer|LINK
I want to use the Photo Manager class in my site but I want to restrict the users from uploading big image files. Am I correct in thinking that the ResizeImageFile function resizes the image in terms of bytes?
As the below 4 lines in the AddPhoto method:
command.Parameters.Add(New SqlParameter("@BytesOriginal", BytesOriginal))
command.Parameters.Add(New SqlParameter("@BytesFull", ResizeImageFile(BytesOriginal, 600)))
command.Parameters.Add(New SqlParameter("@BytesPoster", ResizeImageFile(BytesOriginal, 198)))
command.Parameters.Add(New SqlParameter("@BytesThumb", ResizeImageFile(BytesOriginal, 100)))
So; in the above code, the original file size will be saved along with three other images? How large would a row of data be if the image I was to upload was approx 500kb say? (Is the 600, 198, and 100 values the target in terms of kb's)
I guess i'm just trying to guage what restrictions I would need to put in place so that my db wouldn't get too huge. Hope the above makes sense.
Nov 28, 2007 04:59 PM|AceCorban|LINK
I don't know anything about the resize functions, but you can set the max size of all uploads in your web.config file:
<!-- MAX UPLOAD FILE SIZE: 1024 bytes = 1MB -->
<httpRuntime maxRequestLength="1024" />
Nov 29, 2007 06:27 PM|Scosby|LINK
The ResizeImageFile method will resize the file using the "targetSize" parameter it passes into the CalculateDimensions method, which returns a new Size struct holding the dimensions for your "new" files (based on the input parameter, of course!) that ResizeImageFile
then uses to resize the files. It does this 3 times, once for each of the SQL variables in the Command object Parameters collection: @BytesFull, @BytesPoster, and @BytesThumb
To answer your question - yes, you will get 3 additional files created (and then saved in the the DB) along with the original. I would test a few different images to see what kind of size restrictions you would find acceptable to put in place. Thanks!
Dec 01, 2007 06:03 AM|fizzer|LINK
Thanks for your help. I played with setting the maxRequestLength which worked well. Although not sure how to handle the error if anyone tries to upload a file larger than specified in the config.
What I thought of doing, instead of restricting the size of individual uploads was to restrict users uploading more than say 100MB and then implementing a different subscription level where they would have to pay a subscription fee.
I thought about adding a field in the user's table called currentStorage and update this field each time they upload a new photo. My problem is how do I determine the size of the upload?
Dec 05, 2007 10:10 PM|crf250guy|LINK
There are a variety of ways you could impliment it, but given that an image file can be represented as an array of bytes, imagefile.getlength() will return the size of the file in bytes. Hope this helps =)