0

We are trying to access/play audio files stored on external system from Salesforce Lightning Component. Access to file requires a BASIC authentication with GET method and we don't want users to prompt for username/password when they click on the audio file link (Stored as URL field on Salesforce custom object). We first tried redirecting the user to audio file but no luck. Second option we are trying is, aura component as below which takes Blob from apex controller but it's not working. Any help is greatly appreciated.

<aura:component>
<audio src="{!v.audioFile} type="audio/x-wav"> 
        autoplay="true">
</audio>
</aura:component>

js controller

    ({
    doInit : function(component, event, helper) {
        var recID = component.get("v.recordId");
        console.log("recordID "+recID);
        var action = component.get("c.makeCallout");
        
        action.setParams({
            "recID":recID
        })
       action.setCallback(this, function(response) {
            console.log('get state'+response.getState());
            if (response.getState() == 'SUCCESS') {
                debugger;
               var templateData = response.getReturnValue();
                var byteCharacters = atob(templateData);
                console.log(templateData);
                
                const buf = new Array(byteCharacters.length);

                for (var i = 0; i != byteCharacters.length; ++i)
                buf[i] = byteCharacters.charCodeAt(i);
                
                debugger;
                
                const view = new Uint8Array(buf);
                
                //cast to blob
                const blob = new Blob([view], {
                type: 'audio/x-wav'
                });
               var audio = new Audio(blob);
                audio.play();
                
                component.set("v.audiofile", blob);
                component.set("v.callOutComplete", true);
            }
        });
        $A.enqueueAction(action);
    },
})
3
  • security.stackexchange.com/questions/175695/…
    – identigral
    Commented Sep 21, 2020 at 15:57
  • Thanks for the reply. I have come across this link but however issue is <src> is only taking URL but in our case, we trying to make this work with actual content (blob) of the file without storing it on Salesforce. Commented Sep 22, 2020 at 20:01
  • For the HTML <audio> tag: the src file doesn't have to be stored in Salesforce but it does have to be in a standard audio format. It seems like you're trying to solve the problem of access control by attempting to download the blob and send it to the client. That won't work, at least not the way you have it. Rethink your architecture along the lines of the other link referenced above.
    – identigral
    Commented Sep 22, 2020 at 20:14

0

Browse other questions tagged .