Произошло исключение StorageException. Объект не существует по указанному адресу. Код: -13010 HttpResult: 404 android ⇐ Android
Произошло исключение StorageException. Объект не существует по указанному адресу. Код: -13010 HttpResult: 404 android
fun saveImageFile(filename: String, mimetype: String, bitmap: Bitmap): Uri? { var values = ContentValues() values.put(MediaStore.Images.Media.DISPLAY_NAME, filename) values.put(MediaStore.Images.Media.MIME_TYPE, mimetype) val uri = contentResolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values) Log.d("saveImageFileFun", uri.toString()) try { if (uri != null) { var descripter = contentResolver.openFileDescriptor(uri, "w") if (descripter != null) { val fos = FileOutputStream(descripter.fileDescriptor) bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos) fos.close() return uri } } } catch (e: Exception) { Log.e("Camera", "${e.localizedMessage}") } return null } private fun uploadImage(imageFile : File?) { if(imageFile != null) { val storageRef = Firebase.storage.reference val imageRef = storageRef.child("images/${imageFile.name}") val uploadTask = imageRef.putFile(Uri.fromFile(imageFile)) uploadTask.addOnCompleteListener { task -> if(task.isSuccessful) { imageRef.downloadUrl.addOnSuccessListener { uri -> downloadUrl = uri.toString() } } else { Toast.makeText(this, "이미지 업로드에 실패하였습니다.", Toast.LENGTH_SHORT).show() } } } } fun uriToFile(uri: Uri?): File? { val filePathColumn = arrayOf(MediaStore.Images.Media.DATA) var cursor: Cursor? = null if(uri != null) { cursor = this.contentResolver.query(uri, filePathColumn, null, null, null) } cursor?.moveToFirst() val columnIndex = cursor?.getColumnIndex(filePathColumn[0]) val filePath = cursor?.getString(columnIndex ?: 0) cursor?.close() return filePath?.let { File(it) } } After taking a photo, I plan to upload the photo directly to Firebase and store the uri as data. I am in the process of receiving the URI of the photo I took, converting it to file format, then converting the converted file into URI and putting it in putfile(). But when you proceed like this, you will get a result like this. " StorageException has occurred. Object does not exist at location. Code: -13010 HttpResult: 404"
val uploadTask = imageRef.putFile(Uri.fromFile(imageFile))
The problem seems to occur in this part, and the value contained in the putFile of the code was file:///storage/emulated/0/Pictures/20240304_064313_eewwqq1.jpg. However, when I click dfile:///storage/emulated/0/Pictures/20240304_064313_eewwqq1.jpg in the log, this error occurs: Cannot find file file:///storage/emulated/0/Pictures/20240304_064313_eewwqq1.jpg.
It works when I display the photo I took directly in Image View, but why does the file not exist when I try to save it to Firebase with that uri? After that, the downloadUrl value is Null, so you cannot proceed. I haven't been able to get out for 3 days, so I hope the experts can help me.
Since this is my first question, I don't know if it was the right question, but if I asked the question incorrectly, please let me know so I can ask a more advanced question in the next question.
Источник: https://stackoverflow.com/questions/780 ... de-13010-h
fun saveImageFile(filename: String, mimetype: String, bitmap: Bitmap): Uri? { var values = ContentValues() values.put(MediaStore.Images.Media.DISPLAY_NAME, filename) values.put(MediaStore.Images.Media.MIME_TYPE, mimetype) val uri = contentResolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values) Log.d("saveImageFileFun", uri.toString()) try { if (uri != null) { var descripter = contentResolver.openFileDescriptor(uri, "w") if (descripter != null) { val fos = FileOutputStream(descripter.fileDescriptor) bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos) fos.close() return uri } } } catch (e: Exception) { Log.e("Camera", "${e.localizedMessage}") } return null } private fun uploadImage(imageFile : File?) { if(imageFile != null) { val storageRef = Firebase.storage.reference val imageRef = storageRef.child("images/${imageFile.name}") val uploadTask = imageRef.putFile(Uri.fromFile(imageFile)) uploadTask.addOnCompleteListener { task -> if(task.isSuccessful) { imageRef.downloadUrl.addOnSuccessListener { uri -> downloadUrl = uri.toString() } } else { Toast.makeText(this, "이미지 업로드에 실패하였습니다.", Toast.LENGTH_SHORT).show() } } } } fun uriToFile(uri: Uri?): File? { val filePathColumn = arrayOf(MediaStore.Images.Media.DATA) var cursor: Cursor? = null if(uri != null) { cursor = this.contentResolver.query(uri, filePathColumn, null, null, null) } cursor?.moveToFirst() val columnIndex = cursor?.getColumnIndex(filePathColumn[0]) val filePath = cursor?.getString(columnIndex ?: 0) cursor?.close() return filePath?.let { File(it) } } After taking a photo, I plan to upload the photo directly to Firebase and store the uri as data. I am in the process of receiving the URI of the photo I took, converting it to file format, then converting the converted file into URI and putting it in putfile(). But when you proceed like this, you will get a result like this. " StorageException has occurred. Object does not exist at location. Code: -13010 HttpResult: 404"
val uploadTask = imageRef.putFile(Uri.fromFile(imageFile))
The problem seems to occur in this part, and the value contained in the putFile of the code was file:///storage/emulated/0/Pictures/20240304_064313_eewwqq1.jpg. However, when I click dfile:///storage/emulated/0/Pictures/20240304_064313_eewwqq1.jpg in the log, this error occurs: Cannot find file file:///storage/emulated/0/Pictures/20240304_064313_eewwqq1.jpg.
It works when I display the photo I took directly in Image View, but why does the file not exist when I try to save it to Firebase with that uri? After that, the downloadUrl value is Null, so you cannot proceed. I haven't been able to get out for 3 days, so I hope the experts can help me.
Since this is my first question, I don't know if it was the right question, but if I asked the question incorrectly, please let me know so I can ask a more advanced question in the next question.
Источник: https://stackoverflow.com/questions/780 ... de-13010-h
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение