Back

Little Help Needed : Problem in upploading image in appwrite .

  • 0
  • Android
Shubham
18 Aug, 2023, 18:48

in logcat

TL;DR
User is having trouble uploading an image in the Appwrite app. They are getting an error related to the MIME type being empty. A suggested solution is to check for when the MIME type is empty and fix it. The user shared their code and a stacktrace, and someone suggested using 3 backticks instead of 1 for multiline code. A request was made to share the full stacktrace.
Drake
18 Aug, 2023, 18:57

what's the code that you're running to log the stacktrace?

Shubham
18 Aug, 2023, 19:00

its not stacktrace , its logcat

Drake
18 Aug, 2023, 19:04

would you please share the full stacktrace?

Shubham
18 Aug, 2023, 19:36

java.lang.IllegalArgumentException: No subtype found for: "" at okhttp3.MediaType$Companion.get(MediaType.kt:111) at io.appwrite.Client.chunkedUpload(Client.kt:365) at io.appwrite.services.Storage.createFile(Storage.kt:95) at io.appwrite.services.Storage.createFile$default(Storage.kt:72) at

Drake
18 Aug, 2023, 19:37

Please use 3 backticks instead of 1 for multi line code

Shubham
18 Aug, 2023, 19:38
TypeScript
    at okhttp3.MediaType$Companion.get(MediaType.kt:111)
    at io.appwrite.Client.chunkedUpload(Client.kt:365)
    at io.appwrite.services.Storage.createFile(Storage.kt:95)
    at io.appwrite.services.Storage.createFile$default(Storage.kt:72)
    at ```
Shubham
18 Aug, 2023, 19:38
TypeScript
    at okhttp3.MediaType$Companion.get(MediaType.kt:111)
    at io.appwrite.Client.chunkedUpload(Client.kt:365)
    at io.appwrite.services.Storage.createFile(Storage.kt:95)
    at io.appwrite.services.Storage.createFile$default(Storage.kt:72)
    at ```
Shubham
18 Aug, 2023, 19:38

3 backticks also goes same

Drake
18 Aug, 2023, 19:39

The formatting is a little different if you look closely

Drake
18 Aug, 2023, 19:40

It seems input mime type is an empty string

Shubham
18 Aug, 2023, 19:42

but some image uploaded successfully without any error

Shubham
18 Aug, 2023, 19:43

yes

Drake
18 Aug, 2023, 19:43

Because some images are passing the mime type

Shubham
18 Aug, 2023, 19:43

so what should we do?

Drake
18 Aug, 2023, 19:45

Figure out when the mime type is empty and then fix it

Shubham
18 Aug, 2023, 19:52

its not true , i have printed mime type it gives mime type to both image

Shubham
18 Aug, 2023, 19:52

image/jpeg

Drake
18 Aug, 2023, 19:53

what's yoru code?

Shubham
18 Aug, 2023, 19:54
TypeScript

        val inputStream = contentResolver.openInputStream(PickedImageUri!!)
        val mimeType = contentResolver.getType(PickedImageUri!!)

        val source: BufferedSource = inputStream!!.source().buffer()
        val byteArray = source.readByteArray()

        Log.d("jnm",mimeType.toString())

        userViewModel.saveImage(InputFile.fromBytes(byteArray!!, mimeType ?: "image/jpeg"))
    }```
Drake
18 Aug, 2023, 19:58

in here, before you create the file, would you please log file.mimeType?

Shubham
18 Aug, 2023, 20:03

image/jpeg comes

Shubham
18 Aug, 2023, 20:04

this comes in result

Drake
18 Aug, 2023, 20:05

what's the new code?

Drake
18 Aug, 2023, 20:07

it also looks like you're missing the file name argument to InputFile.fromBytes()

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more