1
0
Fork 0
mirror of synced 2024-05-17 03:02:35 +12:00
appwrite/docs/examples/0.12.x/client-android/kotlin/storage/create-file.md
2022-01-04 12:53:40 +01:00

881 B

import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch import io.appwrite.Client import io.appwrite.services.Storage

class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main)

    val client = Client(applicationContext)
        .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
        .setProject("5df5acd0d48c2") // Your project ID

    val storage = Storage(client)

    GlobalScope.launch {
        val response = storage.createFile(
            fileId = "[FILE_ID]",
            file = File("./path-to-files/image.jpg"),
        )
        val json = response.body?.string()        
    }
}

}