Loading ...
Sorry, an error occurred while loading the content.

Re: Another stupid question...

Expand Messages
  • Josh Chamas
    ... When you say filename, I will assume you mean the file name client side being uploaded... ... Right BrowserFile will give you the name of the file as it
    Message 1 of 14 , Feb 10, 2003
    • 0 Attachment
      Richard Curtis wrote:
      >
      > Following is a post which I hope will clarify what I have been doing up
      > until now, along with some questions regarding the correct way to do this.
      >
      > Until now, I have always handled file uploads in the following way :
      >
      > draw in HTML "<input type="file" name="filename">".
      >
      > Then the form posts in on itself, and I use
      >
      > my $newFile = $Request->Form('filename');
      > $newFile is then passed to a module which will basically do the
      > following (along with a lot more):
      >
      > while ($rets=read($newFile,$line,1024)) { # Read in BINARY
      > my @lin = $line;
      > my $status = append_file($destination_path, $file,\@lin);
      > if (!$status) {
      > return(0,"error storing file on server ($!)");
      > }
      > @lin = ();
      > }
      >
      > This has always worked for me.
      > Now however, I need to not only upload the file to the server, but I
      > need to store the filename in a database (among doing other things with
      > the filename).

      When you say filename, I will assume you mean the file name client side
      being uploaded...

      > So should I be doing :
      > my $newFile = $Request->{FileUpload}{filename};
      > $newFile = $newFile->{BrowserFile};
      >

      Right BrowserFile will give you the name of the file as it was uploaded.

      > ?
      > If not, what should I be doing.
      > What should I call to get handle, and what should I call to get the
      > actual filename ?
      >

      Well, what you have been doing works fine for getting the file handle,
      but you can also get it from;

      $Request->FileUpload('upload_file', 'FileHandle');

      >
      > I am sooo confused !

      Originally, the file upload interface was only available through
      doing it as you do with

      my $fh = $Request->Form('upload_file')

      but as users needed more of the file upload info, I created the
      FileUpload collection to store more of the data. Originally
      MS ASP did not have any native file upload support, so I had not
      API to emulate here, and had to make it up as we went.

      Regards,

      Josh

      ________________________________________________________________
      Josh Chamas, Founder phone:925-552-0128
      Chamas Enterprises Inc. http://www.chamas.com
      NodeWorks Link Checking http://www.nodeworks.com


      ---------------------------------------------------------------------
      To unsubscribe, e-mail: asp-unsubscribe@...
      For additional commands, e-mail: asp-help@...
    • Richard Curtis
      ... I have one further query. If I do the following.. (where filename is the name of the file upload box on the html page) : my $newFileHandle =
      Message 2 of 14 , Feb 11, 2003
      • 0 Attachment
        >> Following is a post which I hope will clarify what I have been doing
        >> up until now, along with some questions regarding the correct way to
        >> do this.
        >>
        >> Until now, I have always handled file uploads in the following way :
        >>
        >> draw in HTML "<input type="file" name="filename">".
        >>
        >> Then the form posts in on itself, and I use
        >>
        >> my $newFile = $Request->Form('filename');
        >> $newFile is then passed to a module which will basically do the
        >> following (along with a lot more):
        >>
        >> while ($rets=read($newFile,$line,1024)) { # Read in BINARY
        >> my @lin = $line;
        >> my $status = append_file($destination_path, $file,\@lin);
        >> if (!$status) {
        >> return(0,"error storing file on server ($!)");
        >> }
        >> @lin = ();
        >> }
        >>
        >> This has always worked for me.
        >> Now however, I need to not only upload the file to the server, but I
        >> need to store the filename in a database (among doing other things
        >> with the filename).
        >
        >
        > When you say filename, I will assume you mean the file name client side
        > being uploaded...
        >
        >> So should I be doing :
        >> my $newFile = $Request->{FileUpload}{filename};
        >> $newFile = $newFile->{BrowserFile};
        >>
        >
        > Right BrowserFile will give you the name of the file as it was uploaded.
        >
        >> ?
        >> If not, what should I be doing.
        >> What should I call to get handle, and what should I call to get the
        >> actual filename ?
        >>
        >
        > Well, what you have been doing works fine for getting the file handle,
        > but you can also get it from;
        >
        > $Request->FileUpload('upload_file', 'FileHandle');
        >
        >>
        >> I am sooo confused !
        >
        >
        > Originally, the file upload interface was only available through
        > doing it as you do with
        >
        > my $fh = $Request->Form('upload_file')
        >
        > but as users needed more of the file upload info, I created the
        > FileUpload collection to store more of the data. Originally
        > MS ASP did not have any native file upload support, so I had not
        > API to emulate here, and had to make it up as we went.
        >


        I have one further query. If I do the following.. (where "filename" is
        the name of the file upload box on the html page) :

        my $newFileHandle = $Request->Form('filename');
        my $newFileName = $Request->FileUpload('filename','BrowserFile');

        Is that the correct syntax ?
        I mean it appear to work, but I still notice something slightly strange.
        If I print them both, they both show the same :

        my $newFileHandle = $Request->Form('filename');
        print "file handle: $newFileHandle <br>";
        my $newFileName = $Request->FileUpload('filename','BrowserFile');
        print "name: $newFileName <br>";

        ... this gives :
        file handle: points.doc
        name: points.doc

        If I print to Data::Dumper as follows :

        print Dumper $newFileHandle . "<br>";
        print Dumper $newFileName . "<br>";

        I get the following output....

        file handle: $VAR1 = bless( \*{'Fh::fh00003points.doc'}, 'Fh' );
        name: $VAR1 = bless( \*{'Fh::fh00003points.doc'}, 'Fh' );

        So, what is the difference.
        When I ask for "browserFile" from the FileUpload request object, why is
        it still a file handle ?

        Maybe I am just being incredibly stupid, but I dont see any difference
        to doing it this way, as to the way I was initially doing it.

        Richard


        ---------------------------------------------------------------------
        To unsubscribe, e-mail: asp-unsubscribe@...
        For additional commands, e-mail: asp-help@...
      • Tim Pushor
        Richard, I m not quite sure why its doing what its doing. I have only done one real project with Apache::ASP that handles file uploads, but again, how I do it
        Message 3 of 14 , Feb 11, 2003
        • 0 Attachment
          Richard,

          I'm not quite sure why its doing what its doing. I have only done one
          real project with Apache::ASP that handles file uploads, but again, how
          I do it is:

          1) Make sure you do a PerlSetVar FileUploadTemp 1 in httpd.conf - this
          will ensure that Apache::ASP actually downloads the file for you and
          puts it into a temporary file. Otherwise you just get a filehandle to
          the file and have to read it and spool it to the file yourself (thats
          how I understood it anyway).

          2) Get the hash with a my $upload_file =
          $Request->{FileUpload}{upload_form_element};

          3) Get the name of the (temporary) file that Apache::ASP downloaded the
          file into: $filename=$upload_file->{TempFile};

          You can then move the file wherever you want. This method works great
          for me.

          Tim


          Richard Curtis wrote:
          <snip>

          >
          > I have one further query. If I do the following.. (where "filename"
          > is the name of the file upload box on the html page) :
          >
          > my $newFileHandle = $Request->Form('filename');
          > my $newFileName = $Request->FileUpload('filename','BrowserFile');
          >
          > Is that the correct syntax ?
          > I mean it appear to work, but I still notice something slightly strange.
          > If I print them both, they both show the same :
          >
          > my $newFileHandle = $Request->Form('filename');
          > print "file handle: $newFileHandle <br>";
          > my $newFileName = $Request->FileUpload('filename','BrowserFile');
          > print "name: $newFileName <br>";
          >
          > ... this gives :
          > file handle: points.doc
          > name: points.doc
          >
          > If I print to Data::Dumper as follows :
          >
          > print Dumper $newFileHandle . "<br>";
          > print Dumper $newFileName . "<br>";
          >
          > I get the following output....
          >
          > file handle: $VAR1 = bless( \*{'Fh::fh00003points.doc'}, 'Fh' );
          > name: $VAR1 = bless( \*{'Fh::fh00003points.doc'}, 'Fh' );
          >
          > So, what is the difference.
          > When I ask for "browserFile" from the FileUpload request object, why
          > is it still a file handle ?
          >
          > Maybe I am just being incredibly stupid, but I dont see any difference
          > to doing it this way, as to the way I was initially doing it.
          >
          > Richard
          >
          >
          > ---------------------------------------------------------------------
          > To unsubscribe, e-mail: asp-unsubscribe@...
          > For additional commands, e-mail: asp-help@...
          >



          ---------------------------------------------------------------------
          To unsubscribe, e-mail: asp-unsubscribe@...
          For additional commands, e-mail: asp-help@...
        • Richard Curtis
          Thanks for your post. I have gone over all of my code, and changed it to exactly how you do it. I have set PerlSetVar FileUploadTemp 1 and restarted apache.
          Message 4 of 14 , Feb 11, 2003
          • 0 Attachment
            Thanks for your post. I have gone over all of my code, and changed it
            to exactly how you do it.
            I have set "PerlSetVar FileUploadTemp 1" and restarted apache.
            All pages which upload a file use:

            my $upload_file = $Request->{FileUpload}{filename};
            # "filename" is the name of the form item.
            my $newFileLocation = $upload_file->{TempFile};
            my $newFileName = $upload_file->{BrowserFile};

            This works fine, although I still have a problem.

            I build an array out of the filenames (taken from $newFileName) which is
            used to add entries for the files into a database.
            The problem is, when I use code such as :

            # this code is using perls DBI interface...
            $add_statement = $dbh->prepare("insert into submission_files
            values(default,'$last_ID',(?),(?),(?))");
            foreach my $file (@$files) {
            # execute
            $add_statement->execute($file,$fileDescriptions[$i],$signature);
            $i++;
            }

            The database dies with the following error:

            Can't bind a reference (Fh=GLOB(0x877e28c)) at
            /home/application/secure/perl/APP/Submissions/AddSubmission.pm line 168.
            <--> , /usr/local/lib/perl5/site_perl/5.6.1/Apache/ASP.pm line 1489

            This shows that the filename returned by my "$newFileName =
            $upload_file->{BrowserFile};" is still actually a file glob.

            I can solve the problem by quoting $file in the
            $add_statement->execute() line, but I am sure this shouldnt be neccesary.

            It appears that the $upload_file->{BrowserFile}; is malfunctioning, or,
            (and more probably), that I am totally misunderstanding this.

            Richard

            > Richard,
            >
            > I'm not quite sure why its doing what its doing. I have only done one
            > real project with Apache::ASP that handles file uploads, but again, how
            > I do it is:
            >
            > 1) Make sure you do a PerlSetVar FileUploadTemp 1 in httpd.conf - this
            > will ensure that Apache::ASP actually downloads the file for you and
            > puts it into a temporary file. Otherwise you just get a filehandle to
            > the file and have to read it and spool it to the file yourself (thats
            > how I understood it anyway).
            >
            > 2) Get the hash with a my $upload_file =
            > $Request->{FileUpload}{upload_form_element};
            >
            > 3) Get the name of the (temporary) file that Apache::ASP downloaded the
            > file into: $filename=$upload_file->{TempFile};
            >
            > You can then move the file wherever you want. This method works great
            > for me.
            >
            > Tim
            <snip>


            ---------------------------------------------------------------------
            To unsubscribe, e-mail: asp-unsubscribe@...
            For additional commands, e-mail: asp-help@...
          • Tim Pushor
            Richard, I m sorry, I too am stumped. Perhaps Josh can help shed some light.. Tim ... To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org For additional
            Message 5 of 14 , Feb 11, 2003
            • 0 Attachment
              Richard,

              I'm sorry, I too am stumped. Perhaps Josh can help shed some light..

              Tim


              Richard Curtis wrote:

              > Thanks for your post. I have gone over all of my code, and changed it
              > to exactly how you do it.
              > I have set "PerlSetVar FileUploadTemp 1" and restarted apache.
              > All pages which upload a file use:
              >
              > my $upload_file = $Request->{FileUpload}{filename};
              > # "filename" is the name of the form item.
              > my $newFileLocation = $upload_file->{TempFile};
              > my $newFileName = $upload_file->{BrowserFile};
              >
              > This works fine, although I still have a problem.
              >
              > I build an array out of the filenames (taken from $newFileName) which
              > is used to add entries for the files into a database.
              > The problem is, when I use code such as :
              >
              > # this code is using perls DBI interface...
              > $add_statement = $dbh->prepare("insert into submission_files
              > values(default,'$last_ID',(?),(?),(?))");
              > foreach my $file (@$files) {
              > # execute
              > $add_statement->execute($file,$fileDescriptions[$i],$signature);
              > $i++;
              > }
              >
              > The database dies with the following error:
              >
              > Can't bind a reference (Fh=GLOB(0x877e28c)) at
              > /home/application/secure/perl/APP/Submissions/AddSubmission.pm line
              > 168. <--> , /usr/local/lib/perl5/site_perl/5.6.1/Apache/ASP.pm line 1489
              >
              > This shows that the filename returned by my "$newFileName =
              > $upload_file->{BrowserFile};" is still actually a file glob.
              >
              > I can solve the problem by quoting $file in the
              > $add_statement->execute() line, but I am sure this shouldnt be neccesary.
              >
              > It appears that the $upload_file->{BrowserFile}; is malfunctioning,
              > or, (and more probably), that I am totally misunderstanding this.
              >
              > Richard
              >
              >> Richard,
              >>
              >> I'm not quite sure why its doing what its doing. I have only done one
              >> real project with Apache::ASP that handles file uploads, but again,
              >> how I do it is:
              >>
              >> 1) Make sure you do a PerlSetVar FileUploadTemp 1 in httpd.conf -
              >> this will ensure that Apache::ASP actually downloads the file for you
              >> and puts it into a temporary file. Otherwise you just get a
              >> filehandle to the file and have to read it and spool it to the file
              >> yourself (thats how I understood it anyway).
              >>
              >> 2) Get the hash with a my $upload_file =
              >> $Request->{FileUpload}{upload_form_element};
              >>
              >> 3) Get the name of the (temporary) file that Apache::ASP downloaded
              >> the file into: $filename=$upload_file->{TempFile};
              >>
              >> You can then move the file wherever you want. This method works great
              >> for me.
              >>
              >> Tim
              >
              > <snip>
              >



              ---------------------------------------------------------------------
              To unsubscribe, e-mail: asp-unsubscribe@...
              For additional commands, e-mail: asp-help@...
            • Josh Chamas
              ... Internally, its actually the same, but the intent is for BrowserFile to reflect just the filename, not be the file handle as well. The fix for this
              Message 6 of 14 , Feb 11, 2003
              • 0 Attachment
                Richard Curtis wrote:
                >
                > This works fine, although I still have a problem.
                >
                > I build an array out of the filenames (taken from $newFileName) which is
                > used to add entries for the files into a database.
                > The problem is, when I use code such as :
                >
                > # this code is using perls DBI interface...
                > $add_statement = $dbh->prepare("insert into submission_files
                > values(default,'$last_ID',(?),(?),(?))");
                > foreach my $file (@$files) {
                > # execute
                > $add_statement->execute($file,$fileDescriptions[$i],$signature);
                > $i++;
                > }
                >
                > The database dies with the following error:
                >
                > Can't bind a reference (Fh=GLOB(0x877e28c)) at
                > /home/application/secure/perl/APP/Submissions/AddSubmission.pm line 168.
                > <--> , /usr/local/lib/perl5/site_perl/5.6.1/Apache/ASP.pm line 1489
                >

                Internally, its actually the same, but the intent is for
                BrowserFile to reflect just the filename, not be the file handle
                as well.

                The fix for this internally is to stringify BrowserFile too,
                as you suggest, and I will apply this fix for the 2.53 release.
                Let me know if you would like an early copy of this.

                Regards,

                Josh
                ________________________________________________________________
                Josh Chamas, Founder phone:925-552-0128
                Chamas Enterprises Inc. http://www.chamas.com
                NodeWorks Link Checking http://www.nodeworks.com


                ---------------------------------------------------------------------
                To unsubscribe, e-mail: asp-unsubscribe@...
                For additional commands, e-mail: asp-help@...
              • Richard Curtis
                ... Thanks for taking the time to read my posts and confirm the issues. I have put a fix into my code to work around this so I dont think I will benefit from a
                Message 7 of 14 , Feb 11, 2003
                • 0 Attachment
                  > Richard Curtis wrote:
                  >
                  >>
                  >> This works fine, although I still have a problem.
                  >>
                  >> I build an array out of the filenames (taken from $newFileName) which
                  >> is used to add entries for the files into a database.
                  >> The problem is, when I use code such as :
                  >>
                  >> # this code is using perls DBI interface...
                  >> $add_statement = $dbh->prepare("insert into submission_files
                  >> values(default,'$last_ID',(?),(?),(?))");
                  >> foreach my $file (@$files) {
                  >> # execute
                  >> $add_statement->execute($file,$fileDescriptions[$i],$signature);
                  >> $i++;
                  >> }
                  >>
                  >> The database dies with the following error:
                  >>
                  >> Can't bind a reference (Fh=GLOB(0x877e28c)) at
                  >> /home/application/secure/perl/APP/Submissions/AddSubmission.pm line
                  >> 168. <--> , /usr/local/lib/perl5/site_perl/5.6.1/Apache/ASP.pm line 1489
                  >>
                  >
                  > Internally, its actually the same, but the intent is for
                  > BrowserFile to reflect just the filename, not be the file handle
                  > as well.
                  >
                  > The fix for this internally is to stringify BrowserFile too,
                  > as you suggest, and I will apply this fix for the 2.53 release.
                  > Let me know if you would like an early copy of this.
                  >

                  Thanks for taking the time to read my posts and confirm the issues.
                  I have put a fix into my code to work around this so I dont think I will
                  benefit from a pre-release copy.

                  Thanks for all the hard work.

                  Richard



                  ---------------------------------------------------------------------
                  To unsubscribe, e-mail: asp-unsubscribe@...
                  For additional commands, e-mail: asp-help@...
                Your message has been successfully submitted and would be delivered to recipients shortly.