B4J Question [BANano] Export to TXT file

Solution
If you mean local you can use this method:

B4X:
Sub btn_Click (event As BANanoEvent)
    Dim theStr As String = $"this is a test
with two lines"$
    SaveAs("alain.txt", "text/plain", theStr)
End Sub

public Sub SaveAs(fileName As String, contentType As String, content As Object)
    Dim document As BANanoObject
    Dim link As BANanoObject
    Dim blob As BANanoObject
    
    document.Initialize("document")
    
    link = document.RunMethod("createElement", "a")
    blob.Initialize2("Blob", Array(Array(content), CreateMap("type": contentType)))
    
    link.SetField("href", BANano.createObjectURL(blob))
    link.SetField("download", fileName)
    link.RunMethod("click", Null)    
    BANano.revokeObjectURL(link.GetField("href"))...

alwaysbusy

Expert
Licensed User
Longtime User
If you mean local you can use this method:

B4X:
Sub btn_Click (event As BANanoEvent)
    Dim theStr As String = $"this is a test
with two lines"$
    SaveAs("alain.txt", "text/plain", theStr)
End Sub

public Sub SaveAs(fileName As String, contentType As String, content As Object)
    Dim document As BANanoObject
    Dim link As BANanoObject
    Dim blob As BANanoObject
    
    document.Initialize("document")
    
    link = document.RunMethod("createElement", "a")
    blob.Initialize2("Blob", Array(Array(content), CreateMap("type": contentType)))
    
    link.SetField("href", BANano.createObjectURL(blob))
    link.SetField("download", fileName)
    link.RunMethod("click", Null)    
    BANano.revokeObjectURL(link.GetField("href"))    
End Sub

Alwaysbusy
 
Upvote 0
Solution
Top