How to download a file from a url in Node JS? [closed] - javascript

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
What's the best way to download a file from a given url? There are times when the url is not the actual url of the file but a "follow to" url which takes us to a file or sometimes a video player is present on the link that plays the video.
How can we ensure the download of the file from those links? Is there any solution to this?

Probably what you want is the request library or it's promise-based version the request-promise library.
The request library will follow 3xx redirects by default, assuming that's what you meant by "follow to" url.
If the link takes you to a web page that contains a video player, what the request library in node.js will download is the web page, not all the other resources referenced in the web page. If you want to download a specific resource used in the web page, then you have to download the web page, parse it with a tool such as cheerio, find the link to the resource you actually want in that web page and then download that specific resource using its URL.
As always with questions here on stack overflow, the more you explain about the eventual final result you're trying to achieve, the better we can help you here. Based on what you've disclosed in the question so far, I think I've answered what you asked, but it feels like there's probably more to the real question than what you've shown so far.

Related

Is it faster to upload one big file or more smaller ones? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
first of all I don't know if question like this already exists, I tried but couldn't find it, so if there is I apologize.
I am trying to stream video by sending each frame to client and then displaying it using Javascript on Website. (so it all works using WebSockets).
I host websocket server on a PC (c# is the language). So, I take screenshot of entire screen and immediately send it over to client.
Now, my question is: should I store multiple frames (say 3?) to one file, then upload that file or should I send frame by frame like I already do? I wonder which one is faster?
Thank you.
They are both going to upload the same size of file, one will be split up though so. They should theoretically upload at the same time- this all depends on bandwith also.
I believe that either way they will be split into packets when they cross networks, so it is more about how you would like to deal with the frames on the client side. If I were you I would let the lower technologies handle details like this (e.g the frameworks or libraries you are using) unless you have a specific purpose for sending the frames in intervals because it will add time on to the upload and it adds more room for things to go wrong with separate loads of frames. E.g; you could send the split frames in the wrong order.

How can i show progress & speed of download [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
First, thanks to help me!
How can i make a file first download to the browser and after that just popup the file... e.g http://mega.nz
I did server side script php, it sends to browser the file in chunks with the content-disposition header and it works!
But i want first download it to browser and show progress & speed.
English isn't my main language...
This is not going to be a complete answer, but I will try and get you started on the right path.
First off, you'll need to use the a filesystem API to download your file to the browser cache. For chrome you can find more info here: https://developer.chrome.com/apps/fileSystem
The API extends through HTML5 though, so you can do this in other browsers as well. See this article for more information: http://www.html5rocks.com/en/tutorials/offline/quota-research/#toc-desktop
Now that is how it works behind the scenes, as far as implementing it yourself, take a look at FileSaver.js
From their Github:
FileSaver.js implements the saveAs() FileSaver interface in browsers that do not natively support it. There is a FileSaver.js demo that demonstrates saving various media types.
FileSaver.js is the solution to saving files on the client-side, and is perfect for webapps that need to generate files, or for saving sensitive information that shouldn't be sent to an external server.
This should allow you to target any modern browser for large file downloading, as well as pausing and resuming downloads.
You may also want to look into NodeJS as there will likely be some packages made already you could leverage in your server application.
The way Mega.nz works is by using the FileSystem API. It writes the file in a "cached" form on your system in an example location as such:
AppData\Local\Google\Chrome\User Data\Default\File System\
What are the benefits of this? Visually none, other than it just makes the feel of downloading something different.
How do you do this? It's not an easy, type this code and you're done! They have clouds set up for this. I would first research FileSystem.

What all tools needed to design/publish websites? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am currently in the process of learning web design. I have learned Java, HTML, SQL, Python and am working on CSS and Javascript. I am learning these because the names of these languages pop up alot when i read about web design. So far i have seen the power of HTML, i can type code and open it as a HTML page and it's a webpage. My question is, what to do when you have all the tools to make the website? How does this website get to be on the World Wide Web? I have done a lot of research and i just don't think i understand the logic behind it. I see that i can purchase a domain name, but how do i bridge the gap between, lets say a simple HTML webpage and getting it to pop up on google? Thanks guys!
The domain register (GoDaddy for example) will point your domain to your hosting server (using the domain name servers or DNS for short), then your hosting server will serve your HTML/PHP/CSS files to anyone requesting them.
Using the submit URL link on google (https://www.google.com/webmasters/tools/submit-url) you can tell Google "hey, i got a new domain, come and check it out!" so Google will index it shortly (may vary between 2-14 days.
You need a server to host it on. The easiest way to do this is to use a cloud service such as Amazon's AWS. In fact, if all you are building is a static html/javascript webpage, you can probably just host it on s3.
http://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteHosting.html

How to get UUID specific to a PC in Chrome extension [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have my PC extension for google chrome, the extension is something like Sync ( Bookmarks, tabs etc). In order to associate each Bookmark and tab with the PC/Desktop/Machine on which it got created/modified. For which i may have to generate my own unique id along with ( for ex:- SerialNo_myown_unique, CPU_No_Myown_unique, MAC_addr_Myownuniqueno etc). So all i want to know is, how do i generate this using Javascript, as most of the blogs and articles i explored have not given clear instructions about how to do it?
Can someone help?
node-uuid will generate RFC compilant UUID strings for you. While these won't depend on the machine they are generated on I don't see why that should be necessary. You can generate a machine uuid once when your extension is installed and associate that with a user account on your service.
Alternatively you could just handle this on your server and request an id from the server after the user logs into his or her account after the extension has been installed.
In general, what you are looking for is called device fingerprinting and is a rather large issue for privacy. That is also why it's (thankfully) rather hard and imprecise to do. The Mozilla Wiki has an interesting collection on some techniques. You can test how unique your browser configuration is on Panopticlick.

How to Inject Javascript code during HTTP call [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I want to inject some javascript code during HTTP call before onload function is called. How can i achieve this? Is this even possible? I have achieved this using Chrome extension but I want some other method to inject the code which works on all other browsers. Something like injecting through URL bar while opening the page. This injection should work on all sites i open.
Another neat way to do it is to have the request go through a proxy. The proxy can inject the JS by modifying the source before it arrives to the client. This is how most ad-supported (ad-injecting) proxies do it.
But then, it's a security issue. That's why, same as having to tell the user to install an extension, you'd have to tell the user to use the proxy. Otherwise, it's a no-go.
Yet another way to do it is to have the owners of the site embed a script that points to a permanent path. Behind that path, you write any script, which may include one that loads some more scripts.
It can be as short as:
<script src="path/to/a/permanent/location"></script>
This is typically how publicly served APIs work, like Google. Behind their permanent path is a script that loads all the APIs you need. But, like I said in the previous section, you need permission, this time in the form of having the webmaster embed the script on the page.

Categories