Returning a blob to a lightning component split error

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
3
down vote

favorite
1












I have a lightning component that queries for a Static Resource and returns the body.



When the lightning component receives the blob data aura throws an error




This page has an error. You might just need to refresh it. Action failed: c:ProductUploader$controller$getTemplate [n.split is not a function] Failing descriptor: c:ProductUploader$controller$getTemplate




I am attempting to download this file to the user using some functionality listed here.



I know I can return a base64 String and convert it using the functions in that related post, but by returning the blob I can reduce about 75% of the code from that post.



Component



<aura:component controller="ProductCreationController">
<aura:handler name="init" value="!this" action="!c.getTemplate"/>
<lightning:layout>

<lightning:layoutItem size="4" />

<lightning:layoutItem size="2">
<!-- place holder for download link -->
</lightning:layoutItem>
<lightning:layoutItem size="2">
<!-- place holder for file upload button -->
</lightning:layoutItem>

<lightning:layoutItem size="4" />
</lightning:layout>
</aura:component>


Controller



(
getTemplate : function(component, event, helper)

var action = component.get(component.get('c.getTemplateBlobData'));
action.setParams();
action.setCallback(this, function(response)
if (response.getState() == 'SUCCESS')
var templateData = response.getReturnValue();
console.log(templateData);

);
$A.enqueueAction(action);

)


Apex



@AuraEnabled
public static Blob getTemplateBlobData()
return [
SELECT Body
FROM StaticResource
WHERE Name = 'New_Product_Template'
].Body;







share|improve this question


























    up vote
    3
    down vote

    favorite
    1












    I have a lightning component that queries for a Static Resource and returns the body.



    When the lightning component receives the blob data aura throws an error




    This page has an error. You might just need to refresh it. Action failed: c:ProductUploader$controller$getTemplate [n.split is not a function] Failing descriptor: c:ProductUploader$controller$getTemplate




    I am attempting to download this file to the user using some functionality listed here.



    I know I can return a base64 String and convert it using the functions in that related post, but by returning the blob I can reduce about 75% of the code from that post.



    Component



    <aura:component controller="ProductCreationController">
    <aura:handler name="init" value="!this" action="!c.getTemplate"/>
    <lightning:layout>

    <lightning:layoutItem size="4" />

    <lightning:layoutItem size="2">
    <!-- place holder for download link -->
    </lightning:layoutItem>
    <lightning:layoutItem size="2">
    <!-- place holder for file upload button -->
    </lightning:layoutItem>

    <lightning:layoutItem size="4" />
    </lightning:layout>
    </aura:component>


    Controller



    (
    getTemplate : function(component, event, helper)

    var action = component.get(component.get('c.getTemplateBlobData'));
    action.setParams();
    action.setCallback(this, function(response)
    if (response.getState() == 'SUCCESS')
    var templateData = response.getReturnValue();
    console.log(templateData);

    );
    $A.enqueueAction(action);

    )


    Apex



    @AuraEnabled
    public static Blob getTemplateBlobData()
    return [
    SELECT Body
    FROM StaticResource
    WHERE Name = 'New_Product_Template'
    ].Body;







    share|improve this question






















      up vote
      3
      down vote

      favorite
      1









      up vote
      3
      down vote

      favorite
      1






      1





      I have a lightning component that queries for a Static Resource and returns the body.



      When the lightning component receives the blob data aura throws an error




      This page has an error. You might just need to refresh it. Action failed: c:ProductUploader$controller$getTemplate [n.split is not a function] Failing descriptor: c:ProductUploader$controller$getTemplate




      I am attempting to download this file to the user using some functionality listed here.



      I know I can return a base64 String and convert it using the functions in that related post, but by returning the blob I can reduce about 75% of the code from that post.



      Component



      <aura:component controller="ProductCreationController">
      <aura:handler name="init" value="!this" action="!c.getTemplate"/>
      <lightning:layout>

      <lightning:layoutItem size="4" />

      <lightning:layoutItem size="2">
      <!-- place holder for download link -->
      </lightning:layoutItem>
      <lightning:layoutItem size="2">
      <!-- place holder for file upload button -->
      </lightning:layoutItem>

      <lightning:layoutItem size="4" />
      </lightning:layout>
      </aura:component>


      Controller



      (
      getTemplate : function(component, event, helper)

      var action = component.get(component.get('c.getTemplateBlobData'));
      action.setParams();
      action.setCallback(this, function(response)
      if (response.getState() == 'SUCCESS')
      var templateData = response.getReturnValue();
      console.log(templateData);

      );
      $A.enqueueAction(action);

      )


      Apex



      @AuraEnabled
      public static Blob getTemplateBlobData()
      return [
      SELECT Body
      FROM StaticResource
      WHERE Name = 'New_Product_Template'
      ].Body;







      share|improve this question












      I have a lightning component that queries for a Static Resource and returns the body.



      When the lightning component receives the blob data aura throws an error




      This page has an error. You might just need to refresh it. Action failed: c:ProductUploader$controller$getTemplate [n.split is not a function] Failing descriptor: c:ProductUploader$controller$getTemplate




      I am attempting to download this file to the user using some functionality listed here.



      I know I can return a base64 String and convert it using the functions in that related post, but by returning the blob I can reduce about 75% of the code from that post.



      Component



      <aura:component controller="ProductCreationController">
      <aura:handler name="init" value="!this" action="!c.getTemplate"/>
      <lightning:layout>

      <lightning:layoutItem size="4" />

      <lightning:layoutItem size="2">
      <!-- place holder for download link -->
      </lightning:layoutItem>
      <lightning:layoutItem size="2">
      <!-- place holder for file upload button -->
      </lightning:layoutItem>

      <lightning:layoutItem size="4" />
      </lightning:layout>
      </aura:component>


      Controller



      (
      getTemplate : function(component, event, helper)

      var action = component.get(component.get('c.getTemplateBlobData'));
      action.setParams();
      action.setCallback(this, function(response)
      if (response.getState() == 'SUCCESS')
      var templateData = response.getReturnValue();
      console.log(templateData);

      );
      $A.enqueueAction(action);

      )


      Apex



      @AuraEnabled
      public static Blob getTemplateBlobData()
      return [
      SELECT Body
      FROM StaticResource
      WHERE Name = 'New_Product_Template'
      ].Body;









      share|improve this question











      share|improve this question




      share|improve this question










      asked Sep 7 at 16:11









      Programatic

      1,08811441




      1,08811441




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          6
          down vote



          accepted










          You must use base-64 encoding if you want to do it this way. The reason why is that internally, Lightning uses JSON, so passing binary data through either way may have unexpected results. If necessary, you might need to return the binary data through several round trips to the server. Alternatively, just make an XMLHttpRequest directly to "/resource/resourceName".



          let xhr = new XMLHttpRequest();
          xhr.open("GET", "/resource/New_Product_Template");
          xhr.onload = $A.getCallback(function()
          // do something with this.response or xhr.response
          );
          xhr.send(null);


          This method bypasses the maximum file limit entirely.






          share|improve this answer






















          • you never fail to answer the tougher questions. Thank you
            – Programatic
            Sep 7 at 16:16










          • @Programatic You're welcome. Always glad to help when I can.
            – sfdcfox
            Sep 7 at 16:19










          • I can actually bypass the javascript entirely by using the $Resource provider. <a href="!$Resource.New_Product_Template" download="New_Product_Template">Download Template</a> Not sure why I didn't think of this in the first place
            – Programatic
            Sep 7 at 16:46






          • 1




            @Programatic I thought you had some sort of other motive where you needed access to the file in your script, too, otherwise I would have recommended the more direct approach. You're certainly right, though, that would be best if that's all you need.
            – sfdcfox
            Sep 7 at 16:49










          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "459"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f231653%2freturning-a-blob-to-a-lightning-component-split-error%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          6
          down vote



          accepted










          You must use base-64 encoding if you want to do it this way. The reason why is that internally, Lightning uses JSON, so passing binary data through either way may have unexpected results. If necessary, you might need to return the binary data through several round trips to the server. Alternatively, just make an XMLHttpRequest directly to "/resource/resourceName".



          let xhr = new XMLHttpRequest();
          xhr.open("GET", "/resource/New_Product_Template");
          xhr.onload = $A.getCallback(function()
          // do something with this.response or xhr.response
          );
          xhr.send(null);


          This method bypasses the maximum file limit entirely.






          share|improve this answer






















          • you never fail to answer the tougher questions. Thank you
            – Programatic
            Sep 7 at 16:16










          • @Programatic You're welcome. Always glad to help when I can.
            – sfdcfox
            Sep 7 at 16:19










          • I can actually bypass the javascript entirely by using the $Resource provider. <a href="!$Resource.New_Product_Template" download="New_Product_Template">Download Template</a> Not sure why I didn't think of this in the first place
            – Programatic
            Sep 7 at 16:46






          • 1




            @Programatic I thought you had some sort of other motive where you needed access to the file in your script, too, otherwise I would have recommended the more direct approach. You're certainly right, though, that would be best if that's all you need.
            – sfdcfox
            Sep 7 at 16:49














          up vote
          6
          down vote



          accepted










          You must use base-64 encoding if you want to do it this way. The reason why is that internally, Lightning uses JSON, so passing binary data through either way may have unexpected results. If necessary, you might need to return the binary data through several round trips to the server. Alternatively, just make an XMLHttpRequest directly to "/resource/resourceName".



          let xhr = new XMLHttpRequest();
          xhr.open("GET", "/resource/New_Product_Template");
          xhr.onload = $A.getCallback(function()
          // do something with this.response or xhr.response
          );
          xhr.send(null);


          This method bypasses the maximum file limit entirely.






          share|improve this answer






















          • you never fail to answer the tougher questions. Thank you
            – Programatic
            Sep 7 at 16:16










          • @Programatic You're welcome. Always glad to help when I can.
            – sfdcfox
            Sep 7 at 16:19










          • I can actually bypass the javascript entirely by using the $Resource provider. <a href="!$Resource.New_Product_Template" download="New_Product_Template">Download Template</a> Not sure why I didn't think of this in the first place
            – Programatic
            Sep 7 at 16:46






          • 1




            @Programatic I thought you had some sort of other motive where you needed access to the file in your script, too, otherwise I would have recommended the more direct approach. You're certainly right, though, that would be best if that's all you need.
            – sfdcfox
            Sep 7 at 16:49












          up vote
          6
          down vote



          accepted







          up vote
          6
          down vote



          accepted






          You must use base-64 encoding if you want to do it this way. The reason why is that internally, Lightning uses JSON, so passing binary data through either way may have unexpected results. If necessary, you might need to return the binary data through several round trips to the server. Alternatively, just make an XMLHttpRequest directly to "/resource/resourceName".



          let xhr = new XMLHttpRequest();
          xhr.open("GET", "/resource/New_Product_Template");
          xhr.onload = $A.getCallback(function()
          // do something with this.response or xhr.response
          );
          xhr.send(null);


          This method bypasses the maximum file limit entirely.






          share|improve this answer














          You must use base-64 encoding if you want to do it this way. The reason why is that internally, Lightning uses JSON, so passing binary data through either way may have unexpected results. If necessary, you might need to return the binary data through several round trips to the server. Alternatively, just make an XMLHttpRequest directly to "/resource/resourceName".



          let xhr = new XMLHttpRequest();
          xhr.open("GET", "/resource/New_Product_Template");
          xhr.onload = $A.getCallback(function()
          // do something with this.response or xhr.response
          );
          xhr.send(null);


          This method bypasses the maximum file limit entirely.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Sep 7 at 16:18

























          answered Sep 7 at 16:15









          sfdcfox

          226k10172387




          226k10172387











          • you never fail to answer the tougher questions. Thank you
            – Programatic
            Sep 7 at 16:16










          • @Programatic You're welcome. Always glad to help when I can.
            – sfdcfox
            Sep 7 at 16:19










          • I can actually bypass the javascript entirely by using the $Resource provider. <a href="!$Resource.New_Product_Template" download="New_Product_Template">Download Template</a> Not sure why I didn't think of this in the first place
            – Programatic
            Sep 7 at 16:46






          • 1




            @Programatic I thought you had some sort of other motive where you needed access to the file in your script, too, otherwise I would have recommended the more direct approach. You're certainly right, though, that would be best if that's all you need.
            – sfdcfox
            Sep 7 at 16:49
















          • you never fail to answer the tougher questions. Thank you
            – Programatic
            Sep 7 at 16:16










          • @Programatic You're welcome. Always glad to help when I can.
            – sfdcfox
            Sep 7 at 16:19










          • I can actually bypass the javascript entirely by using the $Resource provider. <a href="!$Resource.New_Product_Template" download="New_Product_Template">Download Template</a> Not sure why I didn't think of this in the first place
            – Programatic
            Sep 7 at 16:46






          • 1




            @Programatic I thought you had some sort of other motive where you needed access to the file in your script, too, otherwise I would have recommended the more direct approach. You're certainly right, though, that would be best if that's all you need.
            – sfdcfox
            Sep 7 at 16:49















          you never fail to answer the tougher questions. Thank you
          – Programatic
          Sep 7 at 16:16




          you never fail to answer the tougher questions. Thank you
          – Programatic
          Sep 7 at 16:16












          @Programatic You're welcome. Always glad to help when I can.
          – sfdcfox
          Sep 7 at 16:19




          @Programatic You're welcome. Always glad to help when I can.
          – sfdcfox
          Sep 7 at 16:19












          I can actually bypass the javascript entirely by using the $Resource provider. <a href="!$Resource.New_Product_Template" download="New_Product_Template">Download Template</a> Not sure why I didn't think of this in the first place
          – Programatic
          Sep 7 at 16:46




          I can actually bypass the javascript entirely by using the $Resource provider. <a href="!$Resource.New_Product_Template" download="New_Product_Template">Download Template</a> Not sure why I didn't think of this in the first place
          – Programatic
          Sep 7 at 16:46




          1




          1




          @Programatic I thought you had some sort of other motive where you needed access to the file in your script, too, otherwise I would have recommended the more direct approach. You're certainly right, though, that would be best if that's all you need.
          – sfdcfox
          Sep 7 at 16:49




          @Programatic I thought you had some sort of other motive where you needed access to the file in your script, too, otherwise I would have recommended the more direct approach. You're certainly right, though, that would be best if that's all you need.
          – sfdcfox
          Sep 7 at 16:49

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f231653%2freturning-a-blob-to-a-lightning-component-split-error%23new-answer', 'question_page');

          );

          Post as a guest













































































          Comments

          Popular posts from this blog

          What does second last employer means? [closed]

          List of Gilmore Girls characters

          Confectionery