enctype=multipart/form-data on destination page, originating page, or both?

Discussion in 'ASP .Net' started by pbd22, Dec 13, 2006.

  1. pbd22

    pbd22 Guest

    hi.

    could somebody tell me, when uploading a file, i know the form where
    the upload component is must
    have enctype=multipart/form-data but, is the same true for the form
    with the server code to handle the upload?

    thanks.
     
    pbd22, Dec 13, 2006
    #1
    1. Advertising

  2. Re: enctype=multipart/form-data on destination page, originatingpage, or both?

    Hi,

    pbd22 wrote:
    > hi.
    >
    > could somebody tell me, when uploading a file, i know the form where
    > the upload component is must
    > have enctype=multipart/form-data but, is the same true for the form
    > with the server code to handle the upload?
    >
    > thanks.


    I don't understand what you mean. There is one form only, it's on the
    ASPX page, get sent to the client, and then the same form get sent back
    to the server.

    HTH,
    Laurent
    --
    Laurent Bugnion, GalaSoft
    Software engineering: http://www.galasoft-LB.ch
    PhotoAlbum: http://www.galasoft-LB.ch/pictures
    Support children in Calcutta: http://www.calcutta-espoir.ch
     
    Laurent Bugnion, Dec 13, 2006
    #2
    1. Advertising

  3. pbd22

    pbd22 Guest

    thanks for your response Laurent.

    then maybe this is my problem? i have a client - client_upload.aspx
    that has all the javascript and the HTML. but, i have a function call
    that sends the url string through
    a hidden iframe to the server page (server_upload.aspx). the form tag
    on the client has an action of action="server_upload.aspx" inaddition
    to the enctype=multipart/form-data. the response from
    server_upload.aspx is sent back to client_upload.aspx.

    so, that is why i was wondering if both forms need the multipart
    enctype. should i be doing everything on the same aspx page - client
    and server processing? this seems to disgree with what i have read
    online.

    FYI - here is the the onsubmit function of the client_upload.aspx form.

    function callToServer(theFormName) {

    if (!document.createElement) {
    return true
    };

    var IFrameDoc;

    var URL = 'server_upload.aspx' + buildQueryString(theFormName);

    if (!IFrameObj && document.createElement) { //1
    // create the IFrame and assign a reference to the
    // object to our global variable IFrameObj.
    // this will only happen the first time
    // callToServer() is called
    try { //2
    var tempIFrame=document.createElement('iframe');
    tempIFrame.setAttribute('id','RSIFrame');
    tempIFrame.style.border='0px';
    tempIFrame.style.width='0px';
    tempIFrame.style.height='0px';
    IFrameObj = document.body.appendChild(tempIFrame);

    if (document.frames) { //3
    // this is for IE5 Mac, because it will only
    // allow access to the document object
    // of the IFrame if we access it through
    // the document.frames array
    IFrameObj = document.frames['RSIFrame'];
    } // end 3
    } // end 2
    catch(exception) { // 3
    // This is for IE5 PC, which does not allow dynamic creation
    // and manipulation of an iframe object. Instead, we'll fake
    // it up by creating our own objects.
    iframeHTML='\<iframe id="RSIFrame" style="';
    iframeHTML+='border:0px;';
    iframeHTML+='width:0px;';
    iframeHTML+='height:0px;';
    iframeHTML+='"><\/iframe>';
    document.body.innerHTML+=iframeHTML;
    IFrameObj = new Object();
    IFrameObj.document = new Object();
    IFrameObj.document.location = new Object();
    IFrameObj.document.location.iframe =
    document.getElementById('RSIFrame');
    IFrameObj.document.location.replace = function(location) { //4
    this.iframe.src = location;
    } // end 4
    } // end 3
    } // end 2


    Laurent Bugnion wrote:
    > Hi,
    >
    > pbd22 wrote:
    > > hi.
    > >
    > > could somebody tell me, when uploading a file, i know the form where
    > > the upload component is must
    > > have enctype=multipart/form-data but, is the same true for the form
    > > with the server code to handle the upload?
    > >
    > > thanks.

    >
    > I don't understand what you mean. There is one form only, it's on the
    > ASPX page, get sent to the client, and then the same form get sent back
    > to the server.
    >
    > HTH,
    > Laurent
    > --
    > Laurent Bugnion, GalaSoft
    > Software engineering: http://www.galasoft-LB.ch
    > PhotoAlbum: http://www.galasoft-LB.ch/pictures
    > Support children in Calcutta: http://www.calcutta-espoir.ch
     
    pbd22, Dec 13, 2006
    #3
  4. pbd22

    bruce barker Guest

    Re: enctype=multipart/form-data on destination page, originatingpage, or both?

    its still not clear what you are doing. the sample code just creates an
    iframe, there is no post/form logic.
    tag

    couple of things to know.

    if a fileontrol is on the form, asp.net renders the multipart type.

    HttpResponse will only parse the files if the post data has the
    multipart content header. it doesn't care about what the response looks
    like.

    if the posted data is too large, the connection is closed, and the
    asp.net does not continue processing.

    if you use session, requests are serialized.

    -- bruce (sqlwork.com)


    pbd22 wrote:
    > thanks for your response Laurent.
    >
    > then maybe this is my problem? i have a client - client_upload.aspx
    > that has all the javascript and the HTML. but, i have a function call
    > that sends the url string through
    > a hidden iframe to the server page (server_upload.aspx). the form tag
    > on the client has an action of action="server_upload.aspx" inaddition
    > to the enctype=multipart/form-data. the response from
    > server_upload.aspx is sent back to client_upload.aspx.
    >
    > so, that is why i was wondering if both forms need the multipart
    > enctype. should i be doing everything on the same aspx page - client
    > and server processing? this seems to disgree with what i have read
    > online.
    >
    > FYI - here is the the onsubmit function of the client_upload.aspx form.
    >
    > function callToServer(theFormName) {
    >
    > if (!document.createElement) {
    > return true
    > };
    >
    > var IFrameDoc;
    >
    > var URL = 'server_upload.aspx' + buildQueryString(theFormName);
    >
    > if (!IFrameObj && document.createElement) { //1
    > // create the IFrame and assign a reference to the
    > // object to our global variable IFrameObj.
    > // this will only happen the first time
    > // callToServer() is called
    > try { //2
    > var tempIFrame=document.createElement('iframe');
    > tempIFrame.setAttribute('id','RSIFrame');
    > tempIFrame.style.border='0px';
    > tempIFrame.style.width='0px';
    > tempIFrame.style.height='0px';
    > IFrameObj = document.body.appendChild(tempIFrame);
    >
    > if (document.frames) { //3
    > // this is for IE5 Mac, because it will only
    > // allow access to the document object
    > // of the IFrame if we access it through
    > // the document.frames array
    > IFrameObj = document.frames['RSIFrame'];
    > } // end 3
    > } // end 2
    > catch(exception) { // 3
    > // This is for IE5 PC, which does not allow dynamic creation
    > // and manipulation of an iframe object. Instead, we'll fake
    > // it up by creating our own objects.
    > iframeHTML='\<iframe id="RSIFrame" style="';
    > iframeHTML+='border:0px;';
    > iframeHTML+='width:0px;';
    > iframeHTML+='height:0px;';
    > iframeHTML+='"><\/iframe>';
    > document.body.innerHTML+=iframeHTML;
    > IFrameObj = new Object();
    > IFrameObj.document = new Object();
    > IFrameObj.document.location = new Object();
    > IFrameObj.document.location.iframe =
    > document.getElementById('RSIFrame');
    > IFrameObj.document.location.replace = function(location) { //4
    > this.iframe.src = location;
    > } // end 4
    > } // end 3
    > } // end 2
    >
    >
    > Laurent Bugnion wrote:
    >> Hi,
    >>
    >> pbd22 wrote:
    >>> hi.
    >>>
    >>> could somebody tell me, when uploading a file, i know the form where
    >>> the upload component is must
    >>> have enctype=multipart/form-data but, is the same true for the form
    >>> with the server code to handle the upload?
    >>>
    >>> thanks.

    >> I don't understand what you mean. There is one form only, it's on the
    >> ASPX page, get sent to the client, and then the same form get sent back
    >> to the server.
    >>
    >> HTH,
    >> Laurent
    >> --
    >> Laurent Bugnion, GalaSoft
    >> Software engineering: http://www.galasoft-LB.ch
    >> PhotoAlbum: http://www.galasoft-LB.ch/pictures
    >> Support children in Calcutta: http://www.calcutta-espoir.ch

    >
     
    bruce barker, Dec 13, 2006
    #4
  5. pbd22

    pbd22 Guest

    thanks for your response bruce. responses to your response below:

    > there is no post/form logic.


    the attributes in my form tag are changed dynamically as the form loads
    because
    the site.master page has a <form runat=server> tag and all the child
    pages of the
    site.master page load with a <form id=aspnetForm> tag. so, putting a
    from tag
    inside a form tag inside a form tag is a "no", "no"... "no". as a
    result, i am changing the aspnetForm tag when the page loads to look
    like the below:

    window.onload = function() {

    var theForm = document.getElementById('aspnetForm');
    theForm.setAttribute('enctype', 'multipart/form-data');
    theForm.setAttribute('action', 'server_upload.aspx');
    theForm.setAttribute("onsubmit", "return
    callToServer('aspnetForm')");
    theForm.setAttribute('target', 'RSIFrame');

    }

    its ugly, but it works.

    > if a filecontrol is on the form, asp.net renders the multipart type.


    thats my bad, i was using a control but not any more.

    > HttpResponse will only parse the files if the post data has the
    > multipart content header.


    maybe i misunderstand, but i am not using "ajax" (xmlhttprequest) here.
    as far as i
    know, that can't be done with file uploads. what i am doing here is
    passing the file
    upload params through the rendered iframe to the server_upload.aspx
    page where
    the server logic acts on those values.

    this is where things start to fail. the httpfilecollection in the
    server code is always
    length=0 so i am certainly doing something wrong. i am not sure why i
    cant access
    the passed url string but i originally thought that it had something to
    do with how i am
    handling the multipart/form-data declaration. hence my original
    question (and, maybe
    this is what you mean by the above comment).

    i am also unclear how to get a response back to the client since this
    is not a straight xmlhttp request/response. i have the below script on
    the server_upload.aspx page but
    this doesn't allow for passing variables from the server:
    <script type="text/javascript">window.parent.handleResponse()</script>

    sorry for all the verbage but i am really stumped here. if you prefer,
    i can post or email
    my client_upload.aspx and server_upload.aspx code if you don't mind
    taking a look.

    thanks for the help.
    peter

    >
    > if the posted data is too large, the connection is closed, and the
    > asp.net does not continue processing.
    >
    > if you use session, requests are serialized.
    >
    > -- bruce (sqlwork.com)
    >
    >
    > pbd22 wrote:
    > > thanks for your response Laurent.
    > >
    > > then maybe this is my problem? i have a client - client_upload.aspx
    > > that has all the javascript and the HTML. but, i have a function call
    > > that sends the url string through
    > > a hidden iframe to the server page (server_upload.aspx). the form tag
    > > on the client has an action of action="server_upload.aspx" inaddition
    > > to the enctype=multipart/form-data. the response from
    > > server_upload.aspx is sent back to client_upload.aspx.
    > >
    > > so, that is why i was wondering if both forms need the multipart
    > > enctype. should i be doing everything on the same aspx page - client
    > > and server processing? this seems to disgree with what i have read
    > > online.
    > >
    > > FYI - here is the the onsubmit function of the client_upload.aspx form.
    > >
    > > function callToServer(theFormName) {
    > >
    > > if (!document.createElement) {
    > > return true
    > > };
    > >
    > > var IFrameDoc;
    > >
    > > var URL = 'server_upload.aspx' + buildQueryString(theFormName);
    > >
    > > if (!IFrameObj && document.createElement) { //1
    > > // create the IFrame and assign a reference to the
    > > // object to our global variable IFrameObj.
    > > // this will only happen the first time
    > > // callToServer() is called
    > > try { //2
    > > var tempIFrame=document.createElement('iframe');
    > > tempIFrame.setAttribute('id','RSIFrame');
    > > tempIFrame.style.border='0px';
    > > tempIFrame.style.width='0px';
    > > tempIFrame.style.height='0px';
    > > IFrameObj = document.body.appendChild(tempIFrame);
    > >
    > > if (document.frames) { //3
    > > // this is for IE5 Mac, because it will only
    > > // allow access to the document object
    > > // of the IFrame if we access it through
    > > // the document.frames array
    > > IFrameObj = document.frames['RSIFrame'];
    > > } // end 3
    > > } // end 2
    > > catch(exception) { // 3
    > > // This is for IE5 PC, which does not allow dynamic creation
    > > // and manipulation of an iframe object. Instead, we'll fake
    > > // it up by creating our own objects.
    > > iframeHTML='\<iframe id="RSIFrame" style="';
    > > iframeHTML+='border:0px;';
    > > iframeHTML+='width:0px;';
    > > iframeHTML+='height:0px;';
    > > iframeHTML+='"><\/iframe>';
    > > document.body.innerHTML+=iframeHTML;
    > > IFrameObj = new Object();
    > > IFrameObj.document = new Object();
    > > IFrameObj.document.location = new Object();
    > > IFrameObj.document.location.iframe =
    > > document.getElementById('RSIFrame');
    > > IFrameObj.document.location.replace = function(location) { //4
    > > this.iframe.src = location;
    > > } // end 4
    > > } // end 3
    > > } // end 2
    > >
    > >
    > > Laurent Bugnion wrote:
    > >> Hi,
    > >>
    > >> pbd22 wrote:
    > >>> hi.
    > >>>
    > >>> could somebody tell me, when uploading a file, i know the form where
    > >>> the upload component is must
    > >>> have enctype=multipart/form-data but, is the same true for the form
    > >>> with the server code to handle the upload?
    > >>>
    > >>> thanks.
    > >> I don't understand what you mean. There is one form only, it's on the
    > >> ASPX page, get sent to the client, and then the same form get sent back
    > >> to the server.
    > >>
    > >> HTH,
    > >> Laurent
    > >> --
    > >> Laurent Bugnion, GalaSoft
    > >> Software engineering: http://www.galasoft-LB.ch
    > >> PhotoAlbum: http://www.galasoft-LB.ch/pictures
    > >> Support children in Calcutta: http://www.calcutta-espoir.ch

    > >
     
    pbd22, Dec 13, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Li Zhang
    Replies:
    4
    Views:
    6,141
    softip
    Feb 27, 2009
  2. Matt
    Replies:
    8
    Views:
    144,567
    zeeshanakhter2009
    May 26, 2012
  3. Duncan
    Replies:
    0
    Views:
    1,522
    Duncan
    Feb 24, 2006
  4. Matt
    Replies:
    1
    Views:
    11,294
    David Dorward
    Oct 12, 2004
  5. Kevin DeValck
    Replies:
    1
    Views:
    779
    7stud --
    May 17, 2011
Loading...

Share This Page