[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Fwd: 501 -- Almost there...! (plus a few questions)



Sender: daparnin@xxxxxxxxxxxxxxxxxx





Scott,

Wow!  Thanks for the response.  That's a lot for my small brain to
comprehend.  I just got through reading it but I know that I'm going to
have to go back through it several times to understand it all.  I have
studied your example programs but I've got a long way to go to understand
what they are doing and the practical application of how to use them.  I am
learning, albeit slowly.  Even a dry sponge soaks up water eventually.  <g>

As part of the process that I'm putting together the data originates in a
DB2 file.  I was copying it to the IFS since it needed to go out as ASCII.
Maybe now I'll look at going straight to the user space to avoid the
initial translation.

Do you have a rough guess when version 1.10 will be ready?  I probably
won't wait (unless it will be less than a week) but I would like to switch
to it.  For some reason I've just never been overly thrilled by user
spaces.  Maybe I can relate better to IFS files.  Also, if it were easy I
wouldn't learn anything, would I?  Thank.  I appreciate the help.

Dave Parnin
Nishikawa Standard Company
Topeka, IN  46571
daparnin@xxxxxxxxxxxxxxxxxx




                                                                                                              
                      Scott Klement                                                                           
                      <sk@xxxxxxxxxxxxx        To:       ftpapi@xxxxxxxxxxxxx@SMTP@xxx                        
                      com>                     cc:       (bcc: David A Parnin/Topeka/NISCO/SPCO)              
                      Sent by:                 Subject:  Re: Fwd: 501 -- Almost there...!  (plus a few        
                      owner-ftpapi@xxxx         questions)                                                    
                      e.ods.net                                                                               
                                                                                                              
                                                                                                              
                      08/03/2004 12:12                                                                        
                      PM                                                                                      
                      Please respond to                                                                       
                      ftpapi                                                                                  
                                                                                                              
                                                                                                              



Sender: Scott Klement <sk@xxxxxxxxxxxxxxxx>


Hi Dave,

> >From the examples I had seen I had the impression that if you looked at
the
> HTML source of the page, found the fieldname in that source, you could
say
> fieldname=filename and tack on a CRLF.  The HTML source is listed at the
> bottom.  The box for the file name appears to be "File".  The upload
button
> that I want is immediately before the box.

The following is an excerpt from the HTML you that you sent me earlier,
reformatted slightly to make it easier to read:

<FORM ENCTYPE="multipart/form-data" ACTION="/cgi-bin/SomeScript.cgi"
METHOD=POST>
<TD ALIGN=LEFT>
<INPUT TYPE=SUBMIT VALUE="Upload File">
</TD><TD ALIGN=LEFT>
<INPUT TYPE=FILE NAME="File" SIZE=20>
</TD>
</FORM>

<FORM METHOD="POST" ACTION="/cgi-bin/AnotherScript.cgi"
ENCTYPE="application/x-www-form-urlencoded">
<TD ALIGN=LEFT>
<INPUT TYPE="submit" VALUE="Set Ascii" NAME="switch"></TD><TD ALIGN=LEFT>
<INPUT TYPE="submit" VALUE="Chg Passwd" NAME="switch">
</TD>
</FORM>

As you might be able to see, there are two distinct forms here.  Which one
gets submitted depends on which button you click.  If you click a button
in the first form (the "Upload File" button) it will send the file that's
stored in the box to the server referenced by the ACTION="" attribute of
the FORM.  The data that's sent will be encoded using the
"multipart/form-data" (MIME) scheme.  It'll be sent to SomeScript.cgi on
the same server as the HTML page was downloaded from.

If you click a button in the second form, it would instead use the
application/x-www-form-urlencoded encoding scheme and send either the
value "switch=Set+Ascii" or "switch=Chg+Passwd" to AnotherScript.cgi --
also on the same server as the HTML page was downloaded from.

The second form is very similar in concept to what's demonstrated in
EXAMPLE2 of HTTPAPI.  It encodes variables using the "url encoded"
encoding scheme.  This is a very common way of doing things on web sites.
In fact, I've already added a number of new routines to HTTPAPI 1.10
(which isn't yet available for download) that help with encoding these
variables.

However, the first form with the file upload box is somewhat more
difficult -- especially with HTTPAPI 1.9!

The reason it's difficult is that you have to encode your data using the
multipart/form-data scheme.  Since HTTPAPI 1.9 only allows POSTing data
that's on a pointer, you'll have to create a user space and encode your
file into that space.  Then, because HTTPAPI 1.9 translates POST data from
EBCDIC to ASCII, you have to make sure your data is in EBCDIC in the user
space.

What it actually sends to the web server is data that's got MIME
boundaries.  You tell the web server what those boundaries are in the
"content-type" field, which is the 7th parameter to the HTTP_url_post()
API call.   The data for that parameter should look like the following:

 'multipart/form-data; boundary=TestBoundaryBlahWhatever'

Be careful, as the content-type parameter is limited to to 64 bytes.  Also
string "TestBoundaryBlahWhatever" should be something that will never
appear inside the document itself.

Once you've figured out the content-type field, now you have to create the
user space and insert these MIME boundaries into the space.  If you want
to wait for HTTPAPI 1.10 to be released, then you can do it in a stream
file instead of using a user space.

The data with the boundaries added should look like this:

--TestBoundaryBlahWhatever
Content-Disposition: form-data; name="File"; filename="example.txt"
Content-Type: text/plain

<actual file data goes here>
--TestBoundaryBlahWhatever--

Note that the "TestBoundaryBlahWhatever" needs to match what you specified
for the content-type, except that there are two dashes "--" added to the
front
of the opening boundary, and two dashes added to both the start & end of
the closing boundary.

Each of the lines of data shown above should end with a CRLF sequence.

The filename= should match the name of the file that you're uploading.

The content-type field should be the correct MIME type for the data that
you're uploading.  In the example above, the file is a plain text file,
thus "text/plain".  If, for example, the data is a JPG picture, it should
be specified as "image/jpeg".  Etc, etc...

All of the data that you store in the user space needs to be in EBCDIC as
HTTPAPI will translate it from ASCII to EBCDIC.  So even if the data is
NOT text, you have to translate it to EBCDIC when you load it into the
user space so that HTTPAPI will translate it back to the original byte
values when it does it's EBCDIC->ASCII translation.   I know that this is
a headache, so for this reason, the stream file upload in HTTPAPI 1.10
won't do this translation.

Once you've got all of this data laid out in your user space, you can
POST the data in the user space using the same method as EXAMPLE8 shows.
>
> Question #1:  How do I "click" the correct button?
>
> The file name that I want to upload is in the IFS.  When doing this from
a
> browser I specify a path/filename, click the button, and away it goes.  I
> was hoping that the same with the IFS from my RPG.

This would be the case if I added a routine to HTTPAPI that specifically
does this -- but this issue has never come up before, so I've never done
that.

> Question #2:  How do I refer to this file name so that it can be
> uploaded when "the button is clicked"?
>
> When I tried assigning File=/IFSDIR/IFSFILE and posting it I got the
> following back:
> HTTP/1.1 501 Method Not Implemented

The web browser does extra work behind the scenes.  It doesn't only submit
the file's name, but actually encodes and sends the whole file as I
described above.

> Question #3:  What does this mean?

I have a feeling that you didn't encode the File= statement.  It treated
the spaces in the data as a separate method and that left it confused.
Really this question is moot since you don't need to send a file= string
to the server.

> Question #4:  Am I nuts?

Heh... I'll let someone else answer that question :)

At any rate, I'm sorry it took so long to get back to you.  I was out of
town from thursday - monday, and although I had some limited e-mail
access, I didn't have time for a message this long and detailed.  I'm glad
Brad Stone was able to help you out with some of the issues.

I was actually considering writing up some sample code to demonstrate the
process that I described above, but so far I havent' been able to make
time to do that.

---
Scott Klement  http://www.scottklement.com

-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubsribe from the list send mail
to majordomo@xxxxxxxxxxxxx with the body: unsubscribe ftpapi mymailaddr
-----------------------------------------------------------------------


-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubsribe from the list send mail
to majordomo@xxxxxxxxxxxxx with the body: unsubscribe ftpapi mymailaddr
-----------------------------------------------------------------------