wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes Download image/video in JavaScripting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Download image/video in JavaScripting" Watch "Download image/video in JavaScripting" New topic
Author

Download image/video in JavaScripting

Anubh Jain
Ranch Hand

Joined: Apr 09, 2012
Posts: 34
HI ,

Is there any way we can download image and video in JS??

I tried google without any success.

Any pointers to that would alos be appreciated..

Thanks,
Anubhav
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
What do you mean download it via JavaScript?

Eric
Anubh Jain
Ranch Hand

Joined: Apr 09, 2012
Posts: 34

I might not be using proper terms(as i am new and unaware of those) .

I am creating a .js file where i need to download and save the image on my local pc using XMLHTTPREQUEST.

I hope I have made it a little clearer.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61434
    
  67

No, JavaScript cannot write to the client system. Thank goodness!

You can create a link to the resource and the user will be prompted where to save the file.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Anubh Jain
Ranch Hand

Joined: Apr 09, 2012
Posts: 34
Hi Bear,

So, can't I give the path where to download the file in the code itself(i.e. default download location)??

Can you please explain or provide a pointer to some tutorial on how to do this??
That will of great help.

Thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61434
    
  67

Again, you can't. The user will choose where the file goes, not you.
Anubh Jain
Ranch Hand

Joined: Apr 09, 2012
Posts: 34
Ok.

But how do I download the image after user has input the path to download?

Any pointers to that?

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61434
    
  67

All you do is create a link to the image. The browser handles the rest.
Anubh Jain
Ranch Hand

Joined: Apr 09, 2012
Posts: 34
I guess you are assuming that the image is kept in the local storage.

But my problem is I want to download it from server to local storage ...and than load it in browser.

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61434
    
  67

Anubh Jain wrote:I guess you are assuming that the image is kept in the local storage.

I have no idea what you mean by "local storage". I'm assuming that it's on the server.

But my problem is I want to download it from server to local storage ...and than load it in browser.

Once again. Create a link to the image. The user can choose to download anywhere on their disk.

If you want it to automatically display the Save As dialog, you'll need to set the content-disposition header appropriately.
Anubh Jain
Ranch Hand

Joined: Apr 09, 2012
Posts: 34
Ok.

So lets say i have created a link to image on server with URL "http://xyz"

Now using a XMLHTTPREQUEST object, how do i download the image and sisplay it on browser?

Any pointers to that?
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
What does XMLHTTPREQUEST have to do with that? You would create an IMG tag in the page and points its SRC attribute to the image - done.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61434
    
  67

Why would you want to do that? You can't really do much with image data returned from an Ajax response.
Anubh Jain
Ranch Hand

Joined: Apr 09, 2012
Posts: 34
Well, seems I have to go through basic tutorials once again..

I would explain a little about my aim over here..

When my client starts, I want to download a image on my local memory from server along with other details as schedule for when the image is to be displayed.....

When the time given in schedule comes, it should display the image automatically.

I hope I have made it a little clear this time!!!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61434
    
  67

Anubh Jain wrote:I hope I have made it a little clear this time!!!

Not really because you are not using standard terms.

When my client starts

What do you mean by this? What is "your client"? Are you writing a client program? Or do you just mean when you open the web page in a browser?

I want to download a image on my local memory

What is "local memory"? Do you mean your computer?

When the time given in schedule comes, it should display the image automatically.

How? In the browser? What if the user is watching YouTube videos at the time?



Anubh Jain
Ranch Hand

Joined: Apr 09, 2012
Posts: 34
Let me just stick to my problem....

I have a URL of an image.

How do i download the image on my local memory(my PC) using XMLHTTPREQUEST?



That would fix my issue.
Anubh Jain
Ranch Hand

Joined: Apr 09, 2012
Posts: 34
Lets say I have coded:

Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
Before you go any further, you really need to consider these two responses you already got:

Tim Moores wrote:What does XMLHTTPREQUEST have to do with that? You would create an IMG tag in the page and points its SRC attribute to the image - done.


Bear Bibeault wrote:Why would you want to do that? You can't really do much with image data returned from an Ajax response.
Anubh Jain
Ranch Hand

Joined: Apr 09, 2012
Posts: 34
Ok..lets get it this way....



I have an emulator ...which is switched on for all time......
The emulator will connect to server once a day and will download the schedule and data(image/video) to be played at that schedule.

I have downloaded the schedule...but I am unable to download the data(image/video). How do I download this...


Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
Start reading here: http://www.techrepublic.com/article/preloading-and-the-javascript-image-object/5214317
Anubh Jain
Ranch Hand

Joined: Apr 09, 2012
Posts: 34
I went through the link above.....but still I was unable to find what I needed.

How do I write binary data received from server in a file on my local Harddisk?

Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
Not following. You asked about loading images into a web page for the purpose of showing them later; that's what the article is about.

As has been mentioned before, a web page can't download content on its own to the user's disk without the user getting involved, and that's a good thing.

I'm getting the impression, though, the the client you're talking is not really a browser...? In that case you should tell us what kind of client, exactly, this is.
Anubh Jain
Ranch Hand

Joined: Apr 09, 2012
Posts: 34
Ya..it is not a browser....

It is a TV SDK....

Is it possible to call a function of some other language (c/c++/java or any other porogramming language which can download the image) from javascript?

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61434
    
  67

Do you not think that was pertinent information to include on your very first post?
Anubh Jain
Ranch Hand

Joined: Apr 09, 2012
Posts: 34
Appologies for that...

I thought I would have functioned the same way as the browser...but it turned out different...

Sry for that again....

Do you have any solution for this??



 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Download image/video in JavaScripting