B4J Question [SOLVED],[BANano], Help me with banano.GetFileAsArrayBuffer

NGUYEN TUAN ANH

Active Member
Licensed User
Dear All,
Hope you all have a good day off and enjoy the WordCup2022
My Code:
My code:
Dim GetFileArr As ResumableSub = banano.GetFileAsArrayBuffer("./assets/biendong8.sea",Null)
wait for (GetFileArr) Complete (TempArr As Object)
But i can not get Values from TempArr
Could you please help me Get Value from TempArr
Thank you very much
I am waiting for you
Best Regards
 

NGUYEN TUAN ANH

Active Member
Licensed User
Are you sure 'biendong8.sea' exists (and did you pressed the sync button in the IDE?) because this should work. Also, this has to run from a real Web Server else you will get a CORS error.

Alwaysbusy
Thank your reply
I am running im Localhost, and biendong8.sea is existing in my ./assets/
 
Upvote 0

NGUYEN TUAN ANH

Active Member
Licensed User
Try...

Dim TempArr As Object = Banano. Await(banano.GetFileAsArrayBuffer("./assets/biendong8.sea",Null))
Log(TempArr)
Log(TempArr) Result:
  1. ArrayBuffer(30408000)
    1. byteLength: 30408000
    2. [[Prototype]]: ArrayBuffer
    3. [[Int8Array]]: Int8Array(30408000)
    4. [[Uint8Array]]: Uint8Array(30408000)
    5. [[Int16Array]]: Int16Array(15204000)
    6. [[Int32Array]]: Int32Array(7602000)
    7. [[ArrayBufferByteLength]]: 30408000
    8. [[ArrayBufferData]]: 48
But i don't know, how to get some value from ArrayBuffer(30408000)
I had set: Dim TestArr() as Byte = TempArr, But not success
 
Upvote 0

NGUYEN TUAN ANH

Active Member
Licensed User
What are you trying to achieve by using GetFileAsArrayBuffer?
I want to read the Byte array element values stored in the binary file biendong8.sea for further computation.
biendong8.sea is a binary file, I created it on B4A with code:
B4A Code::
Dim TempArr() As Byte
File.WriteBytes(Dir, "biendong8.sea", TempArr)
and on B4A I read it in code:
B4A Code::
Dim TempArr() As Byte = File.ReadBytes(File.DirAssets, "biendong8.sea")
Log(TempArr(1000))
and get a result in debug is: 17
But in B4j BananoVuetifyAD3 I made the code:
B4J BananoVuetifyAD3 Code::
Dim TempArr As Object = Banano. Await(banano.GetFileAsArrayBuffer("./assets/biendong8.sea",Null))
Dim TestArr() as Byte = TempArr
Log(TestArr(1000))
Then only get the result in Debug is: undefined
 
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
Try the following (I used an image file here, but it should work with your type of file too):

ArrayBuffers in JavaScript are 'raw' data and have to be accessed with a 'view'. This view can be a Uint8Array, a Uint16Array, a Uint32Array or a Float64Array
In your case, I believe you need a Uint8Array.

B4X:
Dim GetFileArr As ResumableSub = BANano.GetFileAsArrayBuffer("./assets/banano.jpg",Null)
wait for (GetFileArr) Complete (TempArr As Object)
 
' create a Uint8Array 'view' (an array of bytes)
Dim Uint8View As BANanoObject
Uint8View.Initialize2("Uint8Array", TempArr)
Dim bytes() As Byte = Uint8View ' convert it to a B4J byte array so we can access it more easily
  
Log(bytes(1000))

Alwaysbusy
 
Last edited:
Upvote 0

NGUYEN TUAN ANH

Active Member
Licensed User
Thank you very much
I followed your instructions and was successful as expected
 
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
@NGUYEN TUAN ANH Please mark my post as the answer and change the title of this topic prefix to [BANano] instead of [BANanoVuetifyAD3] as this is a general BANano question. This way, people using pure BANano can also find the answer more easily.

Alwaysbusy
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…