I tried a lot of answers on StackOverflow, but the...
# android
j
I tried a lot of answers on StackOverflow, but the image is sending as text and not as file
b
j
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
you can use
imageView.drawable.toBitmap()
, and then use the second link above to create a file from that bitmap
j
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
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
This is my ImagePicker
This is the ActivityResult of the ImagePicker
The upload function
b
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
I tried that answer too, even sending the file as base64, but keep getting the path and not the file itself
b
i don’t know what
ProgressRequestBody
is, given the other steps, i think that should be
RequestBody.create(MediaType.parse("image/*"), file2)
j
I get this error: I/System.out: ERROR: /data/user/0/com.ryrtech.DoctorOlguin/cache/document/image:16 (No such file or directory)
b
do /data/user/0/com.ryrtech.DoctorOlguin/cache/document/image:16 and
selectedFileUri
match?
j
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
couldn’t hurt to try it
j
Doesn't work, same error
You know somebody who can check that part of the code? I can donate some coffe for the help