Angular - how to test Internet upload speed without backend?

空扰寡人 提交于 2019-12-04 18:17:11

Depending on your webhost, you can make your assets-folder accessible via FTP. Making a FTP-call from javascript (angular is javascript) isn't that difficult. And there are plenty of example and questions about it on the internet (like this)

Why you wouldn't do that:

  • The credentials for your ftp-connection will be accessible in the compiled javascript-code. With a little bit of effort, everyone can find it.
  • Each gate you open through the webhosts firewall, is a extra vulnerability. Thats why everybody will recommend you to add an API endpoint for uploading files so that you keep holding the strings of what may be uploaded.

Edit:

As I read your question again and all the sub-answers, I (think) figured out that you are building an native-like app with no back-end, just an angular-single page front-end application. An I can understand why (you can run this on every platform in an application that supports javascript), but the problem you are encountering is only the first of a whole series.

If this is the case, I wouldn't call it uploadingas you would store it locally.

But the good news is that you have localstoragefor your use to store temporary data on the HDD of the client. It isn't a very large space but it is something...

The assets folder is one of the statically served folders of the Angular app. It is located on the server so you can't add files to it without hitting the server (HTTP server, API, or whatever else...).

Even when running your app on localhost, there's a web server under the hood, so it behaves exactly the same than a deployed application, and you can't add files to the assets folder via the Angular app.

I don't know what exactly you want to do with your uploaded files, but:

  • If you want to use them on client side only, and in one user session, then you can just store the file in a javascript variable and do what you want with it
  • If you want to share them across users, or across user sessions, then you need to store them on the server, and you can't bypass an API or some HTTP server configuration

Based on your clarification in one of your comments:

I'm trying to develop a small speed test application in which user can upload any file from his system to check upload and download speed.

The only way to avoid having you own backend is to use 3rd party API.

There are some dedicated speed test websites, which also provide API access. E.g.:

Note, that many of these APIs are paid services.

Also, I've been able to find this library https://github.com/ddsol/speedtest.net, which might indicate that speedtest.net has some kind of free API tier. But this is up to you to investigate.

This question might also be of help, as it shows using speedtest.net in React Native: Using speedtest.net api with React Native

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!