ajax multipart problem

Discussion in 'Javascript' started by charles, May 18, 2007.

  1. charles

    charles Guest

    Hello,

    I'm trying to use AJAX to send multipart data (not from a client
    file), and I'm using a requestbody with the files separated by a
    boundary, like that:

    var boundStr = 'capitano';
    var boundary = '--' + boundStr;

    var requestbody = [
    boundary,
    'Content-Disposition: file; name="htmlfile";
    filename="hello.html"',
    'Content-Type: text/html',
    '',
    '<html>some file</html>,
    boundary,
    'Content-Disposition: form-data; name="jdk_version"',
    '',
    jdkVersion,
    boundary
    ].join('\n');

    And then I set the headers and send, like that:

    httpRequest.onreadystatechange = requestdone;
    httpRequest.open('POST', url, true);
    httpRequest.setRequestHeader('Content-type', 'multipart/form-
    data; boundary="' + boundStr + '"');
    httpRequest.send(requestbody);

    Now when I try to send the request, I get an error "File not found" in
    Firefox, "Resource not found" in IE. But I'm not reading a file?? I'm
    puzzled.

    Any ideas welcome.
     
    charles, May 18, 2007
    #1
    1. Advertising

  2. On May 18, 9:46 am, charles <> wrote:
    > Hello,
    >
    > I'm trying to use AJAX to send multipart data (not from a client


    > var boundStr = 'capitano';
    > var boundary = '--' + boundStr;
    >
    > var requestbody = [
    > boundary,
    > 'Content-Disposition: file; name="htmlfile";
    > filename="hello.html"',
    > 'Content-Type: text/html',
    > '',
    > '<html>some file</html>,
    > boundary,
    > 'Content-Disposition: form-data; name="jdk_version"',
    > '',
    > jdkVersion,
    > boundary
    > ].join('\n');
    >
    > And then I set the headers and send, like that:
    >
    > httpRequest.onreadystatechange = requestdone;
    > httpRequest.open('POST', url, true);
    > httpRequest.setRequestHeader('Content-type', 'multipart/form-
    > data; boundary="' + boundStr + '"');
    > httpRequest.send(requestbody);
    >
    > Now when I try to send the request, I get an error "File not found" in
    > Firefox, "Resource not found" in IE. But I'm not reading a file?? I'm
    > puzzled.
    >
    > Any ideas welcome.


    Works for me. Can you post the text of the error as listed the
    JavaScript console?
     
    Skye Shaw!@#$, May 20, 2007
    #2
    1. Advertising

  3. charles

    charles Guest

    On 20 mai, 19:18, "Skye Shaw!@#$" <> wrote:
    > On May 18, 9:46 am, charles <> wrote:
    >
    >
    >
    > > Hello,

    >
    > > I'm trying to useAJAXto sendmultipartdata (not from a client
    > > var boundStr = 'capitano';
    > > var boundary = '--' + boundStr;

    >
    > > var requestbody = [
    > > boundary,
    > > 'Content-Disposition: file; name="htmlfile";
    > > filename="hello.html"',
    > > 'Content-Type: text/html',
    > > '',
    > > '<html>some file</html>,
    > > boundary,
    > > 'Content-Disposition: form-data; name="jdk_version"',
    > > '',
    > > jdkVersion,
    > > boundary
    > > ].join('\n');

    >
    > > And then I set the headers and send, like that:

    >
    > > httpRequest.onreadystatechange = requestdone;
    > > httpRequest.open('POST', url, true);
    > > httpRequest.setRequestHeader('Content-type', 'multipart/form-
    > > data; boundary="' + boundStr + '"');
    > > httpRequest.send(requestbody);

    >
    > > Now when I try to send the request, I get an error "File not found" in
    > > Firefox, "Resource not found" in IE. But I'm not reading a file?? I'm
    > > puzzled.

    >
    > > Any ideas welcome.

    >
    > Works for me. Can you post the text of the error as listed the
    > JavaScript console?


    Firefox:

    Error: uncaught exception: [Exception... "Component returned failure
    code: 0x80520012 (NS_ERROR_FILE_NOT_FOUND) [nsIXMLHttpRequest.send]"
    nsresult: "0x80520012 (NS_ERROR_FILE_NOT_FOUND)" location: "JS
    frame :: file:///C:/charles/compile.html :: <TOP_LEVEL> :: line 39"
    data: no]
     
    charles, May 20, 2007
    #3
  4. On May 20, 2:44 pm, charles <> wrote:
    > On 20 mai, 19:18, "SkyeShaw!@#$" <> wrote:
    >
    >
    >
    > > On May 18, 9:46 am, charles <> wrote:

    >
    > > > Hello,

    >
    > > > I'm trying to useAJAXto sendmultipartdata (not from a client
    > > > var boundStr = 'capitano';
    > > > var boundary = '--' + boundStr;

    >
    > > > var requestbody = [
    > > > boundary,
    > > > 'Content-Disposition: file; name="htmlfile";
    > > > filename="hello.html"',
    > > > 'Content-Type: text/html',
    > > > '',
    > > > '<html>some file</html>,
    > > > boundary,
    > > > 'Content-Disposition: form-data; name="jdk_version"',
    > > > '',
    > > > jdkVersion,
    > > > boundary
    > > > ].join('\n');

    >
    > > > And then I set the headers and send, like that:

    >
    > > > httpRequest.onreadystatechange = requestdone;
    > > > httpRequest.open('POST', url, true);
    > > > httpRequest.setRequestHeader('Content-type', 'multipart/form-
    > > > data; boundary="' + boundStr + '"');
    > > > httpRequest.send(requestbody);

    >
    > > > Now when I try to send the request, I get an error "File not found" in
    > > > Firefox, "Resource not found" in IE. But I'm not reading a file?? I'm
    > > > puzzled.

    >
    > > > Any ideas welcome.

    >
    > > Works for me. Can you post the text of the error as listed the
    > > JavaScript console?

    >
    > Firefox:
    >
    > Error: uncaught exception: [Exception... "Component returned failure
    > code: 0x80520012 (NS_ERROR_FILE_NOT_FOUND) [nsIXMLHttpRequest.send]"
    > nsresult: "0x80520012 (NS_ERROR_FILE_NOT_FOUND)" location: "JS
    > frame :: file:///C:/charles/compile.html :: <TOP_LEVEL> :: line 39"
    > data: no]



    You need to test this via a web server, as you are making a XML /Http/
    Request.
     
    Skye Shaw!@#$, May 21, 2007
    #4
  5. charles

    charles Guest


    > > > > var boundStr = 'capitano';
    > > > > var boundary = '--' + boundStr;

    >
    > > > > var requestbody = [
    > > > > boundary,
    > > > > 'Content-Disposition: file; name="htmlfile";
    > > > > filename="hello.html"',
    > > > > 'Content-Type: text/html',
    > > > > '',
    > > > > '<html>some file</html>,
    > > > > boundary,
    > > > > 'Content-Disposition: form-data; name="jdk_version"',
    > > > > '',
    > > > > jdkVersion,
    > > > > boundary
    > > > > ].join('\n');

    >
    > > > > And then I set the headers and send, like that:

    >
    > > > > httpRequest.onreadystatechange = requestdone;
    > > > > httpRequest.open('POST', url, true);
    > > > > httpRequest.setRequestHeader('Content-type', 'multipart/form-
    > > > > data; boundary="' + boundStr + '"');
    > > > > httpRequest.send(requestbody);

    >


    charles> When I try to send the request, I get an error "File not
    charles> found" in Firefox, "Resource not found" in IE. But I'm not
    charles> reading a file?? I'm puzzled.

    shaw> Works for me. Can you post the text of the error as listed the
    shaw> JavaScript console?

    charles> Firefox:
    charles> Error: uncaught exception: [Exception... "Component
    charles> returned failure code: 0x80520012
    charles> (NS_ERROR_FILE_NOT_FOUND) [nsIXMLHttpRequest.send]"
    charles> nsresult: "0x80520012
    charles> (NS_ERROR_FILE_NOT_FOUND)" location: "JS
    charles> frame :: file:///C:/charles/compile.html :: <TOP_LEVEL> ::
    charles> line 39" data: no]

    shaw> You need to test this via a web server, as you are making a
    shaw> XML /Http/ Request.

    Oops... I thought it was enough to connect to a server. Thanks.

    Charles
     
    charles, May 22, 2007
    #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. Alex Sibilev

    multipart/form-data problem

    Alex Sibilev, Oct 3, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    9,726
    Kevin Spencer
    Oct 26, 2004
  2. minnie
    Replies:
    1
    Views:
    737
    Andrew Thompson
    Dec 13, 2006
  3. Replies:
    1
    Views:
    447
  4. NextOne
    Replies:
    3
    Views:
    504
    Martin Honnen
    Sep 30, 2005
  5. Replies:
    4
    Views:
    1,222
Loading...

Share This Page