Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[Common] [Storage] Can't upload data from common module #689

Open
Monabr opened this issue Dec 22, 2024 · 1 comment
Open

[Common] [Storage] Can't upload data from common module #689

Monabr opened this issue Dec 22, 2024 · 1 comment

Comments

@Monabr
Copy link

Monabr commented Dec 22, 2024

Hi. I am trying to upload my bite array to Cloud Storage.

I am doing this .putBytes(Data(byteArray)) but I see that expected declaration have no constructor.

What should I do to upload data from common module?

@Ashkan-san
Copy link

Ashkan-san commented Mar 8, 2025

I found a solution. You need to implement an expect/actual function to format the byteArray to the Data class.

Common Main:
expect fun createDataFromBytes(bytes: ByteArray): Data

Android Main:
actual fun createDataFromBytes(bytes: ByteArray): Data { return Data(bytes) }

IOS Main:
@OptIn(ExperimentalForeignApi::class) actual fun createDataFromBytes(bytes: ByteArray): Data { val nsData = bytes.usePinned { NSData.dataWithBytes(it.addressOf(0), bytes.size.toULong()) } return Data(nsData) }

Probably not the cleanest solution, but it works fine :)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants