简体   繁体   中英

Angular - how to test Internet upload speed without backend?

I want to upload file into folder from which my Angular app is served while running on localhost. I'm not able to find any solution without using backend.

For example I just want to upload an image file and that file should copy in specified folder of the project. This should be done only with Angular without using any Backend script or hitting any API endpoint.

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 uploading as you would store it locally.

But the good news is that you have localstorage for 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. Eg:

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

You can use a third party library such ng-speed-test . For instance here is an Angular library which has an image hosted on a third party server (ie GitHub) to test internet speed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM