• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Download image/video in JavaScripting

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do you mean download it via JavaScript?

Eric
 
Anubh Jain
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Anubh Jain
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Again, you can't. The user will choose where the file goes, not you.
 
Anubh Jain
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok.

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

Any pointers to that?

 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All you do is create a link to the image. The browser handles the rest.
 
Anubh Jain
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Saloon Keeper
Posts: 7590
177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Lets say I have coded:

 
Tim Moores
Saloon Keeper
Posts: 7590
177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Saloon Keeper
Posts: 7590
177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Start reading here: http://www.techrepublic.com/article/preloading-and-the-javascript-image-object/5214317
 
Anubh Jain
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Saloon Keeper
Posts: 7590
177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you not think that was pertinent information to include on your very first post?
 
Anubh Jain
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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??



 
reply
    Bookmark Topic Watch Topic
  • New Topic