1
0
Fork 0
mirror of synced 2024-06-01 10:29:48 +12:00
appwrite/docs/examples/0.12.x/client-android/kotlin/storage/create-file.md

27 lines
881 B
Markdown
Raw Normal View History

2021-11-26 02:07:19 +13:00
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(
2022-01-05 00:53:40 +13:00
fileId = "[FILE_ID]",
2021-11-26 02:07:19 +13:00
file = File("./path-to-files/image.jpg"),
)
val json = response.body?.string()
}
}
}