473,411 Members | 2,019 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

Ajax File upload

5
Hi,

I m using ajax to upload a file. I m using servlets (MultipartFormDataRequest) to upload the file.

My script contains the form data and the file. I m able to get the values of the form data.

Can any one please tell me what i m missing here.

Expand|Select|Wrap|Line Numbers
  1. var boundaryString = 'AaB03x';
  2. var boundary = boundaryString;
  3.  
  4.          var requestBody = setBody(document.getElementById('clientId'),boundary);
  5.          requestBody += setBody(document.getElementById('feed_format'),boundary);
  6.          requestBody += setBody(document.getElementById('delimiter'),boundary);
  7.          requestBody += setBody(document.getElementById('qualifier'),boundary);
  8.          requestBody += setBody(document.getElementById('applicationId'),boundary);
  9.          requestBody += setBody(document.getElementById('applicationName'),boundary);
  10.          //requestBody += setBody(document.getElementById('upload'),boundary);
  11.          requestBody += setFile(document.getElementById('upload'),boundary);
  12.  requestBody += "--" + boundary;
  13.  
  14. function setBody(element, boundary){
  15.         alert(element.name + ", " + element.value);
  16.         var requestBody = "--" + boundary + "\r\n";
  17.         requestBody += "Content-Disposition: form-data; name=\"" + element.name + "\"" + "\r\n\r\n";
  18.         requestBody += element.value + "\r\n";
  19.         return requestBody;
  20. }
  21.  
  22. function setFile(element, boundary){
  23.         alert(element.name + ", " + element.value);
  24.         var requestBody = "--" + boundary + "\r\n";
  25.         requestBody += "Content-Disposition: form-data; name=\"" + element.name + "\"" + "\r\n\r\n";
  26.         //requestBody += element.value + "\r\n\r\r";
  27.         requestBody += "filename="+element.value+"\r\n"+"Content-Type: text/plain\r\n";
  28.         return requestBody;
  29. }
  30.  
The above sets the boundary for the form fields, How do i set content type and disposition elements for file element.



Thanks & Regards
ram
Sep 12 '07 #1
6 2297
ramg80
5
Hi,

I m using ajax to upload a file. I m using servlets (MultipartFormDataRequest) to upload the file.

My script contains the form data and the file. I m able to get the values of the form data.

Can any one please tell me what i m missing here.

Expand|Select|Wrap|Line Numbers
  1. var boundaryString = 'AaB03x';
  2. var boundary = boundaryString;
  3.  
  4.          var requestBody = setBody(document.getElementById('clientId'),boundary);
  5.          requestBody += setBody(document.getElementById('feed_format'),boundary);
  6.          requestBody += setBody(document.getElementById('delimiter'),boundary);
  7.          requestBody += setBody(document.getElementById('qualifier'),boundary);
  8.          requestBody += setBody(document.getElementById('applicationId'),boundary);
  9.          requestBody += setBody(document.getElementById('applicationName'),boundary);
  10.          //requestBody += setBody(document.getElementById('upload'),boundary);
  11.          requestBody += setFile(document.getElementById('upload'),boundary);
  12.  requestBody += "--" + boundary;
  13.  
  14. function setBody(element, boundary){
  15.         alert(element.name + ", " + element.value);
  16.         var requestBody = "--" + boundary + "\r\n";
  17.         requestBody += "Content-Disposition: form-data; name=\"" + element.name + "\"" + "\r\n\r\n";
  18.         requestBody += element.value + "\r\n";
  19.         return requestBody;
  20. }
  21.  
  22. function setFile(element, boundary){
  23.         alert(element.name + ", " + element.value);
  24.         var requestBody = "--" + boundary + "\r\n";
  25.         requestBody += "Content-Disposition: form-data; name=\"" + element.name + "\"" + "\r\n\r\n";
  26.         //requestBody += element.value + "\r\n\r\r";
  27.         requestBody += "filename="+element.value+"\r\n"+"Content-Type: text/plain\r\n";
  28.         return requestBody;
  29. }
  30.  
The above sets the boundary for the form fields, How do i set content type and disposition elements for file element.



Thanks & Regards
ram

Hi,

I m able to upload the file to my server location, But the problem is it stroring the details.


Could any one help me in this regards.

The below is the script which is used to organize the request header.
Expand|Select|Wrap|Line Numbers
  1. function setFile(element, boundary){
  2.         alert(element.name + ", " + element.value);
  3.         var requestBody = "--" + boundary + "\r\n";
  4.         requestBody += "Content-Disposition: form-data; name=\"" + element.name + "\";filename=\"" + element.value +"\""+ "\r\n\r\n";
  5.         requestBody += "Content-Type: text/plain\r\n";
  6.         return requestBody;
  7. }
  8.  
Result is the file is getting uploaded but failed to save the content.. The content in thew file is Content-Type: text/plain



Please reply .

Thanks & regards
Ram
Sep 12 '07 #2
acoder
16,027 Expert Mod 8TB
See this thread. Use an iframe to upload a file without reloading the whole page.
Sep 12 '07 #3
pbmods
5,821 Expert 4TB
Heya, Ram.

Please use CODE tags when posting source code:

[CODE=javascript]
JavaScript code goes here.
[/CODE]
Sep 12 '07 #4
ramg80
5
Heya, Ram.

Please use CODE tags when posting source code:

Expand|Select|Wrap|Line Numbers
  1. JavaScript code goes here.
  2.  
pbmods,

I m new to the community discussions.., Sorry N thanks..
Sep 14 '07 #5
ramg80
5
See this thread. Use an iframe to upload a file without reloading the whole page.
Thanks a lot Buddy. I got the solution
Sep 14 '07 #6
acoder
16,027 Expert Mod 8TB
Glad to hear you got it working.
Sep 14 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: markus.rietzler | last post by:
i want to do (multiple) file upload(s) and display a progress bar. with firefox and safari it is no problem at all. only IE makes some problems. my script is based on ajax-uploader, which can be...
1
by: bsprogs | last post by:
I am currnetly programming a file hosting website in PHP and I am slowly integrating AJAX into the website. Here is my problem: The user uploads the file. The server processes the file and...
3
by: kksandeep | last post by:
i am using this three files to uplod file. i got this file from net but i think these have some error. i am new to this field plz help the script i found is some helpful but not too that i need ...
1
by: gamernaveen | last post by:
Hey guys , am just getting into the AJAX scene and am a noob. I am really worried about Ajax upload , cant figure it out. I have a basic html form , like this <form action="upload.php"...
11
by: kj | last post by:
I would like to convert a form that currently uses the traditional CGI sequence (i.e. the action associated with the form sends a POST request to a server-side CGI script) to one that uses AJAX to...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.