0

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

1 回答 1

0

There is no way to upload a file to Firebase Storage directly from a URL. You will first have to download the data from the URL, and then upload that local data to Firebase as either a String, a local File object, or a Stream.

Also see:

于 2020-12-23T16:06:02.780 回答