【问题标题】:Error occured when using OnGifSelected to send a gif message使用 OnGifSelected 发送 gif 消息时发生错误
【发布时间】:2021-04-02 02:52:13
【问题描述】:

这是我的消息应用程序,每当我尝试从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)

【问题讨论】:

  • 请将示例代码发布为代码,而不是图像。
  • @helvete 刚刚更新

标签: android kotlin firebase-storage giphy-api


【解决方案1】:

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

另见:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-11-11
    • 1970-01-01
    • 2012-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-22
    • 2012-02-12
    相关资源
    最近更新 更多