|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Image Upload problem - tearing hair out here!!browser is failing to upload the file, or the script is failing to catch it. Either way, PostedFile is ending up empty. First of all, I must specify a few things. EVERYTHING IS SET UP IN THE CODE-BEHIND. THAT INCLUDES WRITING OUT ALL OF THE HTML, AND ALL OF THE PAGE ELEMENTS. THERE IS NOTHING WHATSOEVER IS THE WEB PAGE ITSELF, ASIDE FROM THE LINK TO THE CODE-BEHIND .VB FILE. ALSO, CODE IS ONLY SNIPPETS; IT IS NOT THE COMPLETE SCRIPT. THE COMPLETE SCRIPT RUNS AT OVER 3600 LINES, I DOUBT YOU WANT TO SEE THAT HERE. SO DON'T BITCH THAT MY CODE IS NOT "COMPLETE", AS IT ACTUALLY IS, I'M JUST LEAVING OUT REDUNDANT CODE. Sorry for the shouting text, but some people just won't read the details, and get bent out of shape when I have to repeat myself. I have set up the form as follows: myForm.ID = "myForm" myForm.EncType = "multipart/form-data" Controls.Add(myForm) inputfile.id = "ImageUpload" inputfile.Accept = "image/jpg" myForm.Controls.Add(inputfile) when I submit a fully-filled out form, other form elements (such as textareas and input fields) can be easily recovered using "inputfield.value", but using "inputfile.PostedFile" doesn't get me anything back. That is, it is completely empty. When I try to get its contents written out ltrlPreview.Text = inputfile.PostedFile.ContentLength I get "0" When I use ltrlPreview.Text = inputfile.PostedFile.ToString() I get "System.Web.HttpPostedFile" When I try "ImageUpload.PostedFile.ToString()" instead, the script claims that ImageUpload has not been defined (even though it's clearly used as the ID for the inputfile element). When I add: Protected WithEvents ImageUpload As System.Web.UI.HtmlControls.HtmlInputFile to appease the script (which doesn't make sense, since I don't have any raw HTML, everything is created in the code-behind, so this shouldn't have to be implemented) I get: Object reference not set to an instance of an object. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. Stack Trace: [NullReferenceException: Object reference not set to an instance of an object.] TeamMetz.Add30_Preview(Object sender, EventArgs e) +395 System.Web.UI.HtmlControls.HtmlInputButton.OnServerClick(EventArgs e) +108 System.Web.UI.HtmlControls.HtmlInputButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33 System.Web.UI.Page.ProcessRequestMain() +1292 (In fact, when trying about a dozen other methods to retrieve the contents of the uploaded file, the same error occurs. WHY??? What the *f*cking hell* does this error really mean?? Everything on the 'Net about this error seems to make use of doublespeak, smoke & mirrors and 20-syllable tech words that are probably only found in PhD dissertions) The really strange thing is that every other form field element can be easily retrieved by calling its .value content. That is, if I add a text field using: inputtext.id = "Name" inputtext.MaxLength = 50 myForm.Controls.Add(inputtext) all I have to use to access the value I put in the field is: inputtext.value I don't even have to do a Request.Form("Name") to access it (unless I have used more than one inputtext in a form). However, the inputfile field seems to have resisted all attempts to retrieve data from it. I select a proper file, attempt to upload it, and *poof*; nothing happens. Nothing *appears* to have been uploaded, because inputfile.PostedFile is empty. Any help whatsoever would be greatly appreciated. TIA, ...Geshel -- *********************************************************************** * My reply-to is an automatically monitored spam honeypot. Do not use * * it unless you want to be blacklisted by SpamCop. Please reply to my * * first name at my last name dot org. * *********************************************************************** * “I contend that we are both atheists. I just believe in one fewer * * god than you do. When you understand why you dismiss all the other * * possible gods, you will understand why I dismiss yours.†* * - Stephen F. Roberts * *********************************************************************** * “Anyone who believes in Intelligent Design (“creationismâ€) is just * * as ignorant, irrational and ill-educated as someone who believes * * that the world is a flat disc, that the Sun circles the Earth or * * that there really is a tooth fairy. Darwinism has an overwhelming * * foundation of evidence that can be tested and reproduced. * * * * “Intelligent Design, on the other hand, has no evidence at all; not * * one single shred of testable proof. As such, Intelligent Design is * * Religious Mythology, and has no right whatsoever to be in our * * Science classrooms.†- 99.99+% of Scientists * *********************************************************************** Mignon McLaughlin once said that “A nymphomaniac is a woman [who is] as obsessed with sex as the average man.†Unfortunately, since true nymphomaniacs are so rare, this means that it takes an extraordinary woman to keep up with an ordinary man. *********************************************************************** Neo Geshel wrote:
Show quoteHide quote > I am doing something wrong, but I cannot tell what. Either the web Please post your full code.> browser is failing to upload the file, or the script is failing to catch > it. Either way, PostedFile is ending up empty. > > First of all, I must specify a few things. > > EVERYTHING IS SET UP IN THE CODE-BEHIND. THAT INCLUDES WRITING OUT ALL > OF THE HTML, AND ALL OF THE PAGE ELEMENTS. THERE IS NOTHING WHATSOEVER > IS THE WEB PAGE ITSELF, ASIDE FROM THE LINK TO THE CODE-BEHIND .VB FILE. > > ALSO, CODE IS ONLY SNIPPETS; IT IS NOT THE COMPLETE SCRIPT. THE COMPLETE > SCRIPT RUNS AT OVER 3600 LINES, I DOUBT YOU WANT TO SEE THAT HERE. SO > DON'T BITCH THAT MY CODE IS NOT "COMPLETE", AS IT ACTUALLY IS, I'M JUST > LEAVING OUT REDUNDANT CODE. > > Sorry for the shouting text, but some people just won't read the > details, and get bent out of shape when I have to repeat myself. > > I have set up the form as follows: > > myForm.ID = "myForm" > myForm.EncType = "multipart/form-data" > Controls.Add(myForm) > inputfile.id = "ImageUpload" > inputfile.Accept = "image/jpg" > myForm.Controls.Add(inputfile) > > when I submit a fully-filled out form, other form elements (such as > textareas and input fields) can be easily recovered using > "inputfield.value", but using "inputfile.PostedFile" doesn't get me > anything back. That is, it is completely empty. When I try to get its > contents written out > > ltrlPreview.Text = inputfile.PostedFile.ContentLength > > I get "0" > > When I use > > ltrlPreview.Text = inputfile.PostedFile.ToString() > > I get "System.Web.HttpPostedFile" > > When I try "ImageUpload.PostedFile.ToString()" instead, the script > claims that ImageUpload has not been defined (even though it's clearly > used as the ID for the inputfile element). When I add: > > Protected WithEvents ImageUpload As > System.Web.UI.HtmlControls.HtmlInputFile > > to appease the script (which doesn't make sense, since I don't have any > raw HTML, everything is created in the code-behind, so this shouldn't > have to be implemented) I get: > > > Object reference not set to an instance of an object. > Exception Details: System.NullReferenceException: Object reference not > set to an instance of an object. > Stack Trace: > > [NullReferenceException: Object reference not set to an instance of an > object.] > TeamMetz.Add30_Preview(Object sender, EventArgs e) +395 > System.Web.UI.HtmlControls.HtmlInputButton.OnServerClick(EventArgs e) > +108 > > System.Web.UI.HtmlControls.HtmlInputButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String > eventArgument) +57 > System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler > sourceControl, String eventArgument) +18 > System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33 > System.Web.UI.Page.ProcessRequestMain() +1292 > > > (In fact, when trying about a dozen other methods to retrieve the > contents of the uploaded file, the same error occurs. WHY??? What the > *f*cking hell* does this error really mean?? Everything on the 'Net > about this error seems to make use of doublespeak, smoke & mirrors and > 20-syllable tech words that are probably only found in PhD dissertions) > > The really strange thing is that every other form field element can be > easily retrieved by calling its .value content. That is, if I add a text > field using: > > inputtext.id = "Name" > inputtext.MaxLength = 50 > myForm.Controls.Add(inputtext) > > all I have to use to access the value I put in the field is: > > inputtext.value > > I don't even have to do a Request.Form("Name") to access it (unless I > have used more than one inputtext in a form). However, the inputfile > field seems to have resisted all attempts to retrieve data from it. I > select a proper file, attempt to upload it, and *poof*; nothing happens. > Nothing *appears* to have been uploaded, because inputfile.PostedFile is > empty. > > Any help whatsoever would be greatly appreciated. > > TIA, > ...Geshel Only joking. The error message "Object reference not set to an instance of an object" usually means you've declared a variable but have not created an instance of it, for example. Assuming I have a placeholder on a page called plhTest: Dim objTextbox As TextBox objTextbox.Text = "Hello World" plhTest.Controls.Add(objTextbox) This would give the object reference error message. I've declared a variable of type textbox but I haven't created an instance using New: Dim objTextbox As New TextBox objTextbox.Text = "Hello World" plhTest.Controls.Add(objTextbox) Or if you prefer: Dim objTextbox As TextBox objTextbox = New TextBox objTextbox.Text = "Hello World" plhTest.Controls.Add(objTextbox) With regard to the upload, is a file created on the server at all? If not check the permissions on the folder you are trying to write to. Here's some simple test code if you want to try this Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As _ System.EventArgs) Handles btnUpload.Click Dim strUploadPath As String = Server.MapPath("~/imguploads/") Dim fileOK As Boolean = False Dim strFileExt As String Dim strAllowedExt As String() = {".jpg", ".jpeg", ".png", ".gif"} If fupImage.HasFile Then strFileExt = System.IO.Path.GetExtension(fupImage.FileName).ToLower() For i As Integer = 0 To strAllowedExt.Length - 1 If strFileExt = strAllowedExt(i) Then Try fupImage.PostedFile.SaveAs(strUploadPath & _ fupImage.FileName) Catch ex As Exception lblError.Text = ex.Message.ToString End Try End If Next End If End Sub Just add an upload control (fupImage) a label (lblError) and a button (btnUpload) to a page and create a folder called imguploads in the root of the website. Tony B wrote:
Show quoteHide quote > Please post your full code. The file is being placed into a database. Also, when I attempt to parse > > > > > Only joking. > > The error message "Object reference not set to an instance of an object" > usually means you've declared a variable but have not created an > instance of it, for example. > > Assuming I have a placeholder on a page called plhTest: > > Dim objTextbox As TextBox > objTextbox.Text = "Hello World" > plhTest.Controls.Add(objTextbox) > > This would give the object reference error message. I've declared a > variable of type textbox but I haven't created an instance using New: > > Dim objTextbox As New TextBox > objTextbox.Text = "Hello World" > plhTest.Controls.Add(objTextbox) > > Or if you prefer: > > Dim objTextbox As TextBox > objTextbox = New TextBox > objTextbox.Text = "Hello World" > plhTest.Controls.Add(objTextbox) > > With regard to the upload, is a file created on the server at all? If > not check the permissions on the folder you are trying to write to. > > > Here's some simple test code if you want to try this > > Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As _ > System.EventArgs) Handles btnUpload.Click > Dim strUploadPath As String = Server.MapPath("~/imguploads/") > Dim fileOK As Boolean = False > Dim strFileExt As String > Dim strAllowedExt As String() = {".jpg", ".jpeg", ".png", ".gif"} > > If fupImage.HasFile Then > strFileExt = System.IO.Path.GetExtension(fupImage.FileName).ToLower() > > For i As Integer = 0 To strAllowedExt.Length - 1 > If strFileExt = strAllowedExt(i) Then > Try > fupImage.PostedFile.SaveAs(strUploadPath & _ > fupImage.FileName) > Catch ex As Exception > lblError.Text = ex.Message.ToString > End Try > > End If > Next > End If > End Sub > > Just add an upload control (fupImage) a label (lblError) and a button > (btnUpload) to a page and create a folder called imguploads in the root > of the website. the file (either by ID value, ImageUpload.PostedFile.ContentLength or by control name, uploadfile.PostedFile.ContentLength) it always comes out to zero, regardless of file. It's as if the browser never uploaded the file to begin with. VERY FRUSTRATING!! TIA ...Geshel -- *********************************************************************** * My reply-to is an automatically monitored spam honeypot. Do not use * * it unless you want to be blacklisted by SpamCop. Please reply to my * * first name at my last name dot org. * *********************************************************************** * “I contend that we are both atheists. I just believe in one fewer * * god than you do. When you understand why you dismiss all the other * * possible gods, you will understand why I dismiss yours.†* * - Stephen F. Roberts * *********************************************************************** * “Anyone who believes in Intelligent Design (“creationismâ€) is just * * as ignorant, irrational and ill-educated as someone who believes * * that the world is a flat disc, that the Sun circles the Earth or * * that there really is a tooth fairy. Darwinism has an overwhelming * * foundation of evidence that can be tested and reproduced. * * * * “Intelligent Design, on the other hand, has no evidence at all; not * * one single shred of testable proof. As such, Intelligent Design is * * Religious Mythology, and has no right whatsoever to be in our * * Science classrooms.†- 99.99+% of Scientists * *********************************************************************** Mignon McLaughlin once said that “A nymphomaniac is a woman [who is] as obsessed with sex as the average man.†Unfortunately, since true nymphomaniacs are so rare, this means that it takes an extraordinary woman to keep up with an ordinary man. *********************************************************************** Neo Geshel wrote:
> it certainly sounds like it could be something wrong with the browser. > The file is being placed into a database. Also, when I attempt to parse > the file (either by ID value, ImageUpload.PostedFile.ContentLength or by > control name, uploadfile.PostedFile.ContentLength) it always comes out > to zero, regardless of file. It's as if the browser never uploaded the > file to begin with. > > VERY FRUSTRATING!! > > TIA > ...Geshel Does it have a virus checker/personal firewall that could be blocking the upload? Out of interest, try that code I gave you earlier to see if the browser is uploading files at all. Tony Tony B wrote:
Show quoteHide quote > Neo Geshel wrote: Actually, is there any way a Request.Form("ImageUpload") can be tweaked > > >> The file is being placed into a database. Also, when I attempt to >> parse the file (either by ID value, >> ImageUpload.PostedFile.ContentLength or by control name, >> uploadfile.PostedFile.ContentLength) it always comes out to zero, >> regardless of file. It's as if the browser never uploaded the file to >> begin with. >> >> VERY FRUSTRATING!! >> >> TIA >> ...Geshel > > it certainly sounds like it could be something wrong with the browser. > Does it have a virus checker/personal firewall that could be blocking > the upload? > > Out of interest, try that code I gave you earlier to see if the browser > is uploading files at all. > > Tony to provide the uploaded image data? Just curious. ...Geshel -- *********************************************************************** * My reply-to is an automatically monitored spam honeypot. Do not use * * it unless you want to be blacklisted by SpamCop. Please reply to my * * first name at my last name dot org. * *********************************************************************** * “I contend that we are both atheists. I just believe in one fewer * * god than you do. When you understand why you dismiss all the other * * possible gods, you will understand why I dismiss yours.†* * - Stephen F. Roberts * *********************************************************************** * “Anyone who believes in Intelligent Design (“creationismâ€) is just * * as ignorant, irrational and ill-educated as someone who believes * * that the world is a flat disc, that the Sun circles the Earth or * * that there really is a tooth fairy. Darwinism has an overwhelming * * foundation of evidence that can be tested and reproduced. * * * * “Intelligent Design, on the other hand, has no evidence at all; not * * one single shred of testable proof. As such, Intelligent Design is * * Religious Mythology, and has no right whatsoever to be in our * * Science classrooms.†- 99.99+% of Scientists * *********************************************************************** Mignon McLaughlin once said that “A nymphomaniac is a woman [who is] as obsessed with sex as the average man.†Unfortunately, since true nymphomaniacs are so rare, this means that it takes an extraordinary woman to keep up with an ordinary man. *********************************************************************** I think I managed to find out what is going wrong.
It appears that Firefox is the problem. I can't check it on IE, because the method of previewing the images prior to submission into the database is too advanced for IE to use (that is, I use <img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAY.... to preview the form contents prior to a formal database submission, which IE is to primitive and out-of-date to handle). However, everything works fine with Opera. I can upload images, no problem. Any ideas if 1.5.0.2 is the culprit?? TIA. ...Geshel -- *********************************************************************** * My reply-to is an automatically monitored spam honeypot. Do not use * * it unless you want to be blacklisted by SpamCop. Please reply to my * * first name at my last name dot org. * *********************************************************************** * “I contend that we are both atheists. I just believe in one fewer * * god than you do. When you understand why you dismiss all the other * * possible gods, you will understand why I dismiss yours.†* * - Stephen F. Roberts * *********************************************************************** * “Anyone who believes in Intelligent Design (“creationismâ€) is just * * as ignorant, irrational and ill-educated as someone who believes * * that the world is a flat disc, that the Sun circles the Earth or * * that there really is a tooth fairy. Darwinism has an overwhelming * * foundation of evidence that can be tested and reproduced. * * * * “Intelligent Design, on the other hand, has no evidence at all; not * * one single shred of testable proof. As such, Intelligent Design is * * Religious Mythology, and has no right whatsoever to be in our * * Science classrooms.†- 99.99+% of Scientists * *********************************************************************** Mignon McLaughlin once said that “A nymphomaniac is a woman [who is] as obsessed with sex as the average man.†Unfortunately, since true nymphomaniacs are so rare, this means that it takes an extraordinary woman to keep up with an ordinary man. *********************************************************************** Neo Geshel wrote:
Show quoteHide quote > I think I managed to find out what is going wrong. Confirmed. It is either 1.5.0.2 or one of the extensions I have > > It appears that Firefox is the problem. I can't check it on IE, because > the method of previewing the images prior to submission into the > database is too advanced for IE to use (that is, I use <img > src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAY.... to preview the > form contents prior to a formal database submission, which IE is to > primitive and out-of-date to handle). However, everything works fine > with Opera. I can upload images, no problem. > > Any ideas if 1.5.0.2 is the culprit?? > > TIA. > ...Geshel installed. I just tested it from my server using 1.5.0.1, and everything worked out perfectly. Any ideas if it *is* 1.5.0.2, or if I have to look at my extensions? TIA ...Geshel -- *********************************************************************** * My reply-to is an automatically monitored spam honeypot. Do not use * * it unless you want to be blacklisted by SpamCop. Please reply to my * * first name at my last name dot org. * *********************************************************************** * “I contend that we are both atheists. I just believe in one fewer * * god than you do. When you understand why you dismiss all the other * * possible gods, you will understand why I dismiss yours.†* * - Stephen F. Roberts * *********************************************************************** * “Anyone who believes in Intelligent Design (“creationismâ€) is just * * as ignorant, irrational and ill-educated as someone who believes * * that the world is a flat disc, that the Sun circles the Earth or * * that there really is a tooth fairy. Darwinism has an overwhelming * * foundation of evidence that can be tested and reproduced. * * * * “Intelligent Design, on the other hand, has no evidence at all; not * * one single shred of testable proof. As such, Intelligent Design is * * Religious Mythology, and has no right whatsoever to be in our * * Science classrooms.†- 99.99+% of Scientists * *********************************************************************** Mignon McLaughlin once said that “A nymphomaniac is a woman [who is] as obsessed with sex as the average man.†Unfortunately, since true nymphomaniacs are so rare, this means that it takes an extraordinary woman to keep up with an ordinary man. *********************************************************************** Neo Geshel wrote:
Show quoteHide quote > I think I managed to find out what is going wrong. Just updated Firefox on my server to 1.5.0.2 - and no problemo. Looks > > It appears that Firefox is the problem. I can't check it on IE, because > the method of previewing the images prior to submission into the > database is too advanced for IE to use (that is, I use <img > src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAY.... to preview the > form contents prior to a formal database submission, which IE is to > primitive and out-of-date to handle). However, everything works fine > with Opera. I can upload images, no problem. > > Any ideas if 1.5.0.2 is the culprit?? > > TIA. > ...Geshel like it's gotta be the Extensions that I've got installed. Which really sux, because my client has got a few of the same. At least I can rule a few out (which my server has as well), but that still leaves a good half-dozen or more. =( Thanks for all the help. Does anyone know the extensions well enough to pick the culprit out of a list if I give it to them? The ones that my workstation has (that my server doesn't) are: Adblock Adblock filterset.g updater add bookmark here DOM inspector Google pagerank status image toolbar mozilla spellcheck libraries (forced install) MR Tech local install Popups Must Die (forced install) Popup Sound Rankquest SEO toolbar Resize search box SoundDialog (forced install) Web Developer Granted, about half wouldn't interfere, but it could be any of the rest. TIA ...Geshel -- *********************************************************************** * My reply-to is an automatically monitored spam honeypot. Do not use * * it unless you want to be blacklisted by SpamCop. Please reply to my * * first name at my last name dot org. * *********************************************************************** * “I contend that we are both atheists. I just believe in one fewer * * god than you do. When you understand why you dismiss all the other * * possible gods, you will understand why I dismiss yours.†* * - Stephen F. Roberts * *********************************************************************** * “Anyone who believes in Intelligent Design (“creationismâ€) is just * * as ignorant, irrational and ill-educated as someone who believes * * that the world is a flat disc, that the Sun circles the Earth or * * that there really is a tooth fairy. Darwinism has an overwhelming * * foundation of evidence that can be tested and reproduced. * * * * “Intelligent Design, on the other hand, has no evidence at all; not * * one single shred of testable proof. As such, Intelligent Design is * * Religious Mythology, and has no right whatsoever to be in our * * Science classrooms.†- 99.99+% of Scientists * *********************************************************************** Mignon McLaughlin once said that “A nymphomaniac is a woman [who is] as obsessed with sex as the average man.†Unfortunately, since true nymphomaniacs are so rare, this means that it takes an extraordinary woman to keep up with an ordinary man. ***********************************************************************
date calculations
Do loop memory consumption? "Send To Mail Recipient" Saving outlook email attachment? ListBox Control Classes and collections vs. virtual tables (datasets) Display All Domain Names on the Network Recursion with a Tree View and checkboxes Translating VB6 Code to kill the screen saver. GetType question |
|||||||||||||||||||||||