Techiio-author
Started by Bradley ReidNov 6, 2021

Open
javascript code to download files from Azure blob storage

2 VIEWES 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 2 VIEWES SHARE

There's HTML code written for the download button. The complete SharePoint 2013 hosted software functionality has js code. There's a WCF solution the use of c# to get information from sap gadget. There may be one page in the application which has a download button. As soon as clicked using the user, the file must get downloaded from azure blob garage. Kindly assist with how we can obtain this.

1 Replies

Techiio-commentatorPrince Mishra replied 3 months ago0 likes0 dislikes
  • firstly made a textarea where all the text input will be issued.
  • make an anchor tag using createElement property and then assigning it the download and href attribute.
  • encodeURIComponent will encode everything with special meaning, so you use it for components of URIs. 
    For example, if we have text like “Hello: Geek ?”, there are special characters in this, so encodeURIComponent will encode them and append it for further usage.
  • data:text/plain; charset=utf-8 is the attribute value of href (like href=” “), it specifies that the value must be of type text and with UTF-8 type encoding. The click() method simulates a mouse-click on an element.
  • After that we simply call our download function with the text from textarea and our file name “GFG.txt” as parameters on the input button with id ‘btn’.

<!DOCTYPE html>

<html>

<body>

<style>

p {

color: green;

}

</style>

<p>

How to trigger a file download when

clicking an HTML button or JavaScript?

<p>

<textarea id="text">

Welcome to GeeksforGeeks

</textarea>

<br/>

<input type="button" id="btn"

value="Download" />

<script>

function download(file, text) {

//creating an invisible element

var element = document.createElement('a');

element.setAttribute('href',

'data:text/plain;charset=utf-8, '

+ encodeURIComponent(text));

element.setAttribute('download', file);

// Above code is equivalent to

// <a href="path of file" download="file name">

document.body.appendChild(element);

//onClick property

element.click();

document.body.removeChild(element);

}

// Start file download.

document.getElementById("btn")

.addEventListener("click", function() {

// Generate download of hello.txt

// file with some content

var text = document.getElementById("text").value;

var filename = "GFG.txt";

download(filename, text);

}, false);

</script>

</body>

</html>

You must be Logged in to reply
Trending Technologies
15
Software40
DevOps48
Frontend Development24
Backend Development20
Server Administration17
Linux Administration26
Data Center24
Sentry24
Terraform23
Ansible83
Docker70
Penetration Testing16
Kubernetes21
NGINX20
JenkinsX17
Recommended Blogs
1
Techiio-logo

Techiio is on the journey to build an ocean of technical knowledge, scouring the emerging stars in process and proffering them to the corporate world.

Follow us on:

Subscribe to get latest updates

You can unsubscribe anytime from getting updates from us
Developed and maintained by Wikiance
Developed and maintained by Wikiance