如何解决当我尝试将gif uri放入文件中以上传到Firebase存储时,FileInputStream无法正常工作
我正在尝试将选定的gif from giphy dialog fragment上传到Firebase存储。供参考,我使用的是giphy API
问题是输入/输出不起作用,我的应用仅加载了空的filenameGif而没有输入的网址。
override fun onGifSelected(media: Media,searchTerm: String?,selectedContentType: GPHContentType){
gif_url = image!!.gifUrl
fileNameGif = Environment.getExternalStorageDirectory().absolutePath + File.separator + "/gif"
if (fileNameGif == null) {
return;
}
try {
val output = FileOutputStream(fileNameGif)
val input = FileInputStream(gif_url)
val inputChannel: FileChannel = input.getChannel()
val outputChannel: FileChannel = output.getChannel()
inputChannel.transferTo(0,inputChannel.size(),outputChannel)
output.close()
input.close()
Toast.makeText(this@ChatActivity,"gif selected",Toast.LENGTH_SHORT).show()
} catch (e: FileNotFoundException) {
e.printStackTrace()
} catch (e: IOException) {
e.printStackTrace()
}
}
在这里我尝试上传gif,但是上传为空
val gif = Uri.fromFile(File(fileNameGif))
val filenamePath = "Gif Images/" + firebaseUser!!.uid + System.currentTimeMillis()
val storageReference = FirebaseStorage.getInstance().getReference(filenamePath)
//upload image
storageReference.putFile(gif!!)
.addOnSuccessListener { t
似乎正在发生的事情是我的代码只承认了这一部分:
fileNameGif = Environment.getExternalStorageDirectory().absolutePath + File.separator + "/gif"
并忽略此:
if (fileNameGif == null) {
return;
}
try {
val output = FileOutputStream(fileNameGif)
val input = FileInputStream(gif_url)
val inputChannel: FileChannel = input.getChannel()
val outputChannel: FileChannel = output.getChannel()
inputChannel.transferTo(0,Toast.LENGTH_SHORT).show()
} catch (e: FileNotFoundException) {
e.printStackTrace()
} catch (e: IOException) {
e.printStackTrace()
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。