https://kotlinlang.org logo
#android
Title
# android
j

JOHSE

09/11/2019, 8:51 PM
I tried a lot of answers on StackOverflow, but the image is sending as text and not as file
b

Brian

09/11/2019, 9:32 PM
j

JOHSE

09/12/2019, 2:32 AM
I'm using retrofit now, the code seems work but i'm getting an exception with the lateinit var inside the fragment i'm using for this.
Ok, i fix the runtime error, now i'm getting the error "/document/image:16 (No such file or directory)"
There's a way i can get the file from an imageView instead from an Uri?
b

Brian

09/12/2019, 1:50 PM
you can use
imageView.drawable.toBitmap()
, and then use the second link above to create a file from that bitmap
j

JOHSE

09/12/2019, 9:49 PM
I'm still getting the error (No such file or directory), but now is showing me the full path of the file, i really don't know what to do
b

Brian

09/13/2019, 1:56 PM
i think you’d need to post more code - it sounds like the bitmap isn’t getting saved as a temporary file for one reason or another, so then you can’t upload it
j

JOHSE

09/13/2019, 3:43 PM
This is my ImagePicker
This is the ActivityResult of the ImagePicker
The upload function
b

Brian

09/13/2019, 3:54 PM
and does it crash at
val file2 = File(context!!.cacheDir, selectedPath)
or somewhere else?
and what if you try the
imageView.drawable.toBitmap()
method combined with this? https://stackoverflow.com/questions/45828401/how-to-post-a-bitmap-to-a-server-using-retrofit-android
as well as stepping through with the debugger to see just what might be missing
j

JOHSE

09/13/2019, 3:59 PM
I tried that answer too, even sending the file as base64, but keep getting the path and not the file itself
b

Brian

09/13/2019, 4:03 PM
i don’t know what
ProgressRequestBody
is, given the other steps, i think that should be
RequestBody.create(MediaType.parse("image/*"), file2)
j

JOHSE

09/13/2019, 4:10 PM
I get this error: I/System.out: ERROR: /data/user/0/com.ryrtech.DoctorOlguin/cache/document/image:16 (No such file or directory)
b

Brian

09/13/2019, 4:16 PM
do /data/user/0/com.ryrtech.DoctorOlguin/cache/document/image:16 and
selectedFileUri
match?
j

JOHSE

09/13/2019, 4:17 PM
Give me a second
They don't
I think i found the error, the fun is trying to reach this path "/documents/image:16" but the real path is "content://com.android.providers.media.documents/document/image%3A16"
Should i add the missing part?
b

Brian

09/13/2019, 4:54 PM
couldn’t hurt to try it
j

JOHSE

09/13/2019, 5:01 PM
Doesn't work, same error
You know somebody who can check that part of the code? I can donate some coffe for the help