0

I have a requirement to develop download all types of files from a folder as zip in angular. I am new in angular.How to do it?

I don't know how to do this can you please help?

  • where do the files exist? and what are you using as your backend ? – Kaneki21 Feb 11 '23 at 10:27
  • My files are in C:/Files. I am using asp.net core API as back end – Al Amin Suzan Feb 11 '23 at 10:29
  • you have to serve the files from your backend, have public/private endpoints in your backend so that they can be accessed from your UI. Try [this](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/static-files?view=aspnetcore-7.0) – Kaneki21 Feb 11 '23 at 10:32
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Feb 11 '23 at 10:34
  • Can you please explain in detail as I am new to this area? – Al Amin Suzan Feb 11 '23 at 10:34
  • Angular is running on client side so it does not have the access to files which you want to serve, so for serving correct files you need to have backend server which can serve the files wherever they exists – Kaneki21 Feb 11 '23 at 10:36
  • As I need to serve the file . Will I do this from my asp.net core API. Then how can I access this folder in angular – Al Amin Suzan Feb 11 '23 at 10:46

1 Answers1

0

From what I understand you need to:

  1. build an endpoint in your backend that your Angular (client) can sent a get request.This is a bit out of scope for angular but you may find an answer here
  2. use the HttpClientModule to download the files. This is usually done in a service; your component will call that service, the service will create a GET request via the HttpClientModule.
  3. When you get the response back, you'll need to handle it differently than other json response. You can view this as a reference. I'd recommend using the propr responseType:'arraybuffer' solution which is less "hacky" event though the blob one will work as well.
Chen Peleg
  • 953
  • 10
  • 16