Save QRCode in Amazon S3 after it has been rendered

I need to save the generated QRCode in Amazon S3 and I am using the OnAfterRenderAsync method for the same. I am however getting a error saying that QRCodeGenerator does not have any such method. Can you please advise? I am using the following for reference: https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.BarcodeGenerator.SfQRCodeGenerator.html#Syncfusion_Blazor_BarcodeGenerator_SfQRCodeGenerator_OnAfterRenderAsync_System_Boolean_


Code to save generated BarCode in Amazon S3:

protected async Task QRCodeGenerator_OnAfterRenderAsync(bool firstRender)

    {

    }



9 Replies

AR Aravind Ravi Syncfusion Team December 10, 2021 12:10 PM UTC

Hi Ajit, 

In the barcode, we does not have support to save the barcode. Instead of save the barcode, you can export the barcode as image and save it in your database. By using the Export method, we can able to export the barcode and save it for later use. Please refer to the below documentation for how to export the barcode 


Regards 
Aravind Ravi


AG ajit goel December 11, 2021 02:40 AM UTC

Would you be able to advise me on how to do it via a simple code sample? The Export method generates the QR code and downloads it to the client browser.
As far as I looked, no event were exposed that were triggered when the qrcode was rendered successfully(please see my attempt above)



AR Aravind Ravi Syncfusion Team December 13, 2021 01:12 PM UTC

Hi Ajit, 

After the barcode gets rendered, OnAfterRenderAsync blazor event gets triggered. In this event you can save the barcode. The argument parameter firstRender is set to true for the the first time the component instance is rendered. Please refer to below documentation and code snippet 

protected override Task OnAfterRenderAsync(bool firstRender) 
   
        
         return task; 
   


Regards 
Aravind Ravi 



AG ajit goel December 13, 2021 04:27 PM UTC

I dont understand, are you saying that SfQRCodeGenerator has an OnAfterRenderAsync event that we can handle, like below? This does not work, I get a compile error. Similarly, if I just handle the  OnAfterRenderAsync event on the page, without saying that it is a , it will get triggered for every OnAfterRenderAsync event on the page. 


 <SfQRCodeGenerator Width="300px" Height="300px" Value="@UploadedS3FilePath" @ref="QRCodeGenerator" OnAfterRenderAsync="QRCodeGenerator_OnAfterRenderAsync">

        <QRCodeGeneratorDisplayText text="@UploadedS3FilePath" Visibility="false"></QRCodeGeneratorDisplayText>

      </SfQRCodeGenerator>


protected override async Task QRCodeGenerator_OnAfterRenderAsync(bool firstRender)

    {

      //Step 3: Save the barcode to S3.     

    }



AG ajit goel December 15, 2021 02:07 AM UTC

Hello Aravind,Would you have any further updates



AR Aravind Ravi Syncfusion Team December 15, 2021 03:10 AM UTC

Hi Ajit, 

Yes, the OnAfterRenderAsync event gets triggered on every reload or rerendered of component. By using firstRender parameter, you can check if it is render first time or not. On firstRender it is set as true. As we said earlier, we does not have support to save the barcode. By using export method you can get the image base64 string and save it and used it for later purpose. We only have OnAfterRenderAsync event to notify that barcode has rendered. We does not have any other events to notify after barcode gets rendered. 

Regards 
Aravind Ravi 



AG ajit goel December 15, 2021 05:42 AM UTC

Hello Aravind,

I selected an document, uploaded to S3 and set the Value property of the SfQRCodeGenerator  to the UploadedS3FilePath. In the  OnAfterRenderAsync method, I am trying to get the  uploadedBarCodeAsJPG_base64string but I never get the value. Please see  https://www.loom.com/share/b937ab5b4fc14358af6268343ce34e77 here.
What am I missing?

.razor.cs file:

protected override async Task OnAfterRenderAsync(bool firstRender)

    {

      if(firstRender == false && fileuploadedtoS3 == true && QRCodeGenerator!=null)

      {

        //Step 3: Save the barcode to S3.

        var uploadedBarCodeAsJPG_base64string = QRCodeGenerator.ExportAsBase64Image(BarcodeExportType.JPG).Result;<= it never gets this value and move to the next line

        var bytes1 = Convert.FromBase64String(uploadedBarCodeAsJPG_base64string);

//Code to save to Amazon S3

        fileuploadedtoS3 =false;

      }

    }

.razor file:

 @if(string.IsNullOrEmpty(UploadedS3FilePath)==false)

    {

      <SfQRCodeGenerator Width="300px" Height="300px" Value="@UploadedS3FilePath" @ref="QRCodeGenerator">

        <QRCodeGeneratorDisplayText text="@UploadedS3FilePath" Visibility="false"></QRCodeGeneratorDisplayText>

      </SfQRCodeGenerator>

    }





AG ajit goel December 16, 2021 04:51 AM UTC

This question can be closed. I should be able to use a different syncfusion nuget library to generate and save the QR code. 


https://www.syncfusion.com/forums/125757/save-qr-barcode-to-file



AR Aravind Ravi Syncfusion Team December 16, 2021 01:09 PM UTC

Hi Ajit, 

Thanks for the update 

Regards 
Aravind Ravi 


Loader.
Up arrow icon