• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

attaching files through JavaScript

 
indu yeturu
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi , Please help me how to attach files like in Gmail-style using Javascript.

Thanks
indu
[ August 29, 2008: Message edited by: Bear Bibeault ]
 
Angel J Gama
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use an iFrame to upload your files. Have you read the link that David O'Meara sent you for uploading files?
If using an iFrame, you should create one form per attachment, and every html-form should be submitted "within" an iframe. How?

... and so on. Once the servlet has uploaded your file, you'll see the response inside the iframe it was sent.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15441
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We have a separate forum for questions about HTML and JavaScript. I will move this topic to that forum; please follow the link at the top of this page to continue.
 
Stoyan Stefanov
author
Ranch Hand
Posts: 82
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
YUI's Connection Manager (Ajax) abstracts a bit of hard work for you and makes your file upload code look like a normal Ajax request. It's using an iframe behind the scenes.

Or if you want to go fancy, flickr-style, you can use YUI's uploader control. The cool thing about it is that it let's the user upload multiple files in one selection (as in, you hold CTRL and select several files). It's using Flash. Later WordPress versions are using similar type of flash uploader.
 
indu yeturu
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using this JS function to attach a file, as our team wants it to be without AJAX, then, in what way can I upload the files once they are attached?

function addFileInput()
{
var d = document.createElement("div");
var file = document.createElement("input");
file.setAttribute("type","file");
file.setAttribute("name","attachment"+upload_number);
d.appendChild(file);
document.getElementById("moreUploads").appendChild(d);
upload_number++;
}
thanks
indu
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65122
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without using Ajax or an iframe, you'll just need to do a normal form submission. You can;t get away without the server-side code to receive the file. JavaScript cannot upload the file on its own -- it can only initiate the client-side request.
 
Angel J Gama
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using iframes isn't ajax. It's just sending the form in another "window".
YOu could use the same JS function, but instead of append an input file within a div, you can so something like this:
It's probable that I've misspelled some js methods, but that's a way to do it (no ajax).
 
indu yeturu
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot to All..
indu
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65122
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Angel J Gama:
Using iframes isn't ajax

Prior to XMLHttpRequest invisible iframes were used to make "backdoor" requests, and many consider that a form of Ajax. When it comes to file uploads, it's the only way to do it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic