Add pre-condition check

This commit is contained in:
Him188 2020-03-29 12:41:07 +08:00
parent 90ef83e345
commit 04b0287738

View File

@ -116,7 +116,7 @@ suspend fun InputStream.uploadAsImage(contact: Contact): OfflineImage =
*/
@Throws(OverFileSizeMaxException::class)
suspend fun File.uploadAsImage(contact: Contact): OfflineImage {
require(this.exists() && this.canRead())
require(this.isFile && this.exists() && this.canRead()) { "file ${this.path} is not readable" }
return withContext(Dispatchers.IO) { toExternalImage() }.upload(contact)
}