I am trying to send an image to my apollo-graphql server, but I get the following error:
android.system.ErrnoException: open failed: ENOENT (No such file or directory)
This is the Android code:
lifecycleScope.launch {
val response = try {
apolloClient(requireContext()).mutate(
SubirImagenMutation(
imagenData = FileUpload("image/jpg", File(imagen.path!!).toString())
)
).toDeferred().await()
} catch (e: ApolloException) {
Toasts().visualizarToast(requireContext(), getString(R.string.str_err_generico))
return@launch
}
findNavController().navigate(R.id.serviciosFragment)
}
The image path:
/document/1804-2E16:DCIM/definicion-de-persona-min.jpg: open failed: ENOENT (No such file or directory)
App permissions:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Thanks in advance.
not every
URIcan be resolved as strict file path on file system. e.g. some file pickers can return file placed on some cloud storage...in your case
URIpoints on/document/1804-2E16:DCIM/definicion-de-persona-min.jpg, which is malformed for shure. you are probably gettingURIsimilar to this/document/1804-2E16thinking that this is directory path, so you are addingStringfilename, but this isn't how this works... your real original and full "path" to file looks probably like this:no filename, no fileformat, just a "pointer" - an
URIread about FileProviders and check out THIS topic for some info how to obtain access to such files. fixing this "bug" isn't trivial, in short you have to handle some file streams