1

I have an url of the image(Not from salesforce) which is stored in another system.

Can i download that file by providing link to the URL in my Lightning component ?

I have tried with "**lightning:formattedUrl value="https://www.someimage...." />" but it doesn't support download.

0

As per my understanding, you want to download the image, so salesforce will provide download feature with below link and it is only for the documents saved in Salesforce.

You might need to save the image in documents tab of Salesforce and Id needs to be added in below URL.

I don't think Salesforce will allow you to download the external image. We can view it but download until that content is added in Salesforce seems to be difficult.

In case of lightning:formattedUrl, below link will go in "Value" attribute and you can keep "Label" as any free text.

/servlet/servlet.FileDownload?file={Attachment Id}&operationContext=S1

Thanks!

0

Use standard html:

<a href="https://www.someimage...." title="my downloadedfile">

1
  • The above-mentioned code just opens the link in the same tab. Question here is to download the file. – sri_bb Jun 15 '20 at 13:52
0

You'll need to do some workarounds:

<a class="downloader" style="visibility: hidden;"></a>


    fetch(url).then((response) => {
       return response.blob();
    }).then(blob => {
        let link = this.template.querySelector('.downloader');
        link.setAttribute("href", URL.createObjectURL(blob));
        link.setAttribute("download", 'fileName');
        link.click();
    });

Also, add the URL host to Remote Site Settings and CSP policies.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.