微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用 OnGifSelected 发送 gif 消息时出错

如何解决使用 OnGifSelected 发送 gif 消息时出错

这是针对我的消息传递应用程序,每当我尝试从 this GIPHY UI SDK 发送 gif 时,我都会收到此错误:发生未知错误,请检查服务器响应的 HTTP 结果代码和内部异常。

  override fun onGifSelected(media: Media,searchTerm: String?,selectedContentType: GPHContentType) {


   val image = media.images.fixedWidth
        val  gif_url = image!!.gifUrl
        val gifUri = Uri.parse(gif_url)
        
        
        val reference2 = FirebaseDatabase.getInstance().getReference("Friends")
        reference2.child(firebaseUser!!.uid)
                .addListenerForSingleValueEvent(object : ValueEventListener {
                    override fun onDataChange(snapshot: DataSnapshot) {

                        if (snapshot.hasChild(visitorsUid!!)) {
                            //progressDialog
                            val pd = ProgressDialog(this@ChatActivity)
                            pd.setTitle("Please wait...")
                            pd.setMessage("Sending Gif...")
                            pd.setCanceledOnTouchOutside(false)
                            pd.show()

                            val databaseReference = FirebaseDatabase.getInstance().reference
                            //file name and path in firebase storage
                            val filenamePath = "Gif Images/" + firebaseUser!!.uid + System.currentTimeMillis()
                            val storageReference = FirebaseStorage.getInstance().getReference(filenamePath)
                            //upload image
                            storageReference.putFile(gifUri!!)
                                    .addOnSuccessListener { taskSnapshot ->
                                        //image uploaded,get url
                                        val p_uriTask = taskSnapshot.storage.downloadUrl
                                        while (!p_uriTask.isSuccessful);
                                        val p_downloadUri = p_uriTask.result
                                        if (p_uriTask.isSuccessful) {
                                            //image url recieved,save in db
                                            //timestamp
                                            val timestamp = "" + System.currentTimeMillis()

                                            //setup message data
                                            val hashMap = HashMap<String,Any>()
                                            hashMap["sender"] = firebaseUser!!.uid

我认为问题出在这条线

 val gifUri = Uri.parse(gif_url)

我尝试将其上传到我的 Firebase 存储

 storageReference.putFile(gifUri!!)

这是我的 logcat 显示内容

 E/StorageException: No content provider: https://media3.giphy.com/media/iJbxNEqePoPp7l8I0g/200w.gif?cid=e8dbb930ge42y7jitdl6z424143u7ah6bti5nmz7v16mdi53&rid=200w.gif
    java.io.FileNotFoundException: No content provider: https://media3.giphy.com/media/iJbxNEqePoPp7l8I0g/200w.gif?cid=e8dbb930ge42y7jitdl6z424143u7ah6bti5nmz7v16mdi53&rid=200w.gif
        at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1969)
        at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1798)
        at android.content.ContentResolver.openInputStream(ContentResolver.java:1475)

解决方法

无法直接从 URL 将文件上传到 Firebase Storage。您首先必须从 URL 下载数据,然后将 upload that local data to Firebase 下载为字符串、本地 File 对象或 Stream

另见:

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。