This week's book giveaway is in the Reactive Progamming forum.
We're giving away four copies of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams and have Adam Davis on-line!
See this thread for details.
Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

attaching files through JavaScript

 
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 ]
 
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.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • 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.
 
author
Posts: 85
5
PHP
  • 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
 
Marshal
Posts: 67289
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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
Marshal
Posts: 67289
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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.
 
Put the moon back where you found it! We need it for tides and poetry and stuff. Like this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!