Angularjs download a file from api
Above code works on all systems except ios so use these steps if you need this to work on ios Step 1 check if ios stackoverflow. NOTE: developer. Add a comment. AnkitG AnkitG 6, 6 6 gold badges 40 40 silver badges 69 69 bronze badges. How did you use Filesaver. How did you implement it? Enable the link and change its appearance.
Send your file as a base64 string. Thank you PPB, your solution worked for me except for the atob. That wasn't required for me. Erkin Djindjiev Erkin Djindjiev 3 3 silver badges 6 6 bronze badges. Thank you Scott for catching those items. I've refactored and added an explanation. I have gone through array of solutions and this is what I found to have worked great for me. Aleks Andreev 6, 8 8 gold badges 27 27 silver badges 36 36 bronze badges. OneGhana OneGhana 61 5 5 bronze badges.
In your component i. Shivani Jadhav Shivani Jadhav 1. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Podcast Who is building clouds for the independent developer? Enjoyed it? Share the love! Share this content Opens in a new window Opens in a new window Opens in a new window Opens in a new window Opens in a new window.
He is currently working as a senior software developer in Edinburgh, UK. He is the primary author and the founder of onthecode. Noe 19 Dec Reply. Excelente Post. Me salvo la vida. Leave a Reply Cancel reply Comment. URL window. I hope this helps. FileName; if! Open, FileAccess. ToBase64String bytes ; response. Enable the link and change its appearance.
Send your file as a base64 string. This time we can skip the creation of the folder because the CLI will do that for us. The behavior of the DownloadComponent will follow the general pattern — it will call the FileService, handle the response, and propagate it back to its parent component. To accomplish that, we have to add logic to the download. With this, we can wrap up the implementation of the download operation. To choose a file to download, we first need to list those files somewhere in the application and trigger the download request with the help of the UI components.
As mentioned in the beginning, we will load a list of users from the database and take their corresponding profile pictures. But to have something to show, we first need to create some users. On the homepage of the application, by entering credentials and uploading a picture, we can successfully create a User.
When we add a user, the profile picture will also automatically appear in a folder inside our application. For the sake of simplicity, we will show them below the user creation form. Each photo in the list will have an associated download button which will trigger the download for that particular file.
For the realization of the idea of iterating through a list of users, we first need to load the users from the database. Luckily, we already have a method in the app. Here, we also added the selector for the DownloadComponent so its template renders next to each profile picture. By clicking the download button, we will get a message that we have hit the download end-point:. With this implementation, we are manipulating the user data that we read from the database, selecting image properties, and showing them.
But what if we want to read the files directly from a folder? To be able to read from a folder, we need its path.
When we access the desired folder, we pick up the files with specific extensions since we only want pictures. That way we will get paths for each file and render them on the UI as we do now by reading from the database. Firstly, we are going to add a new end-point to our FileController. We will fill it with the necessary logic for reading.