Skip to content

Instantly share code, notes, and snippets.

@dan085
Last active January 14, 2020 14:52
Show Gist options
  • Save dan085/ffdb492290f0c0eeed7bf03531eac664 to your computer and use it in GitHub Desktop.
Save dan085/ffdb492290f0c0eeed7bf03531eac664 to your computer and use it in GitHub Desktop.
Librería ion para subir archivos al servidor
Ion.with(ctx.applicationContext)
.load(AppConfig.URL_IMAGE)
.setTimeout(15000)
// .setHeader("Authorization", "b7 " + chatService.get_token())
.uploadProgress { downloaded, total ->
println("$downloaded / $total")
val percentage2 = (0.5 + downloaded.toDouble() / total.toDouble() * 100).toInt()
println(percentage2)
//progressbar_picture.setProgress(percentage2);
}
.setMultipartParameter("mobile", KEY_MOBILE)
.setMultipartFile("image_upload", picture_file)
.asJsonObject()
.setCallback { e, result ->
if (e != null) {
layout_loading_register.visibility = View.GONE
layout_view_register.visibility = View.VISIBLE
registerErrorMsg.text = chatService!!.resource(ctx).getString(R.string.tv_warning_message_connect_error) + " " + chatService!!.resource(ctx).getString(R.string.Try_again_please)
registerErrorMsg.setTextColor(chatService!!.resource(ctx).getColor(R.color.azul_playlist))
} else {
val msg = result.get("msg").asString
if (msg == "true") {
File(ctx.applicationContext.filesDir.absolutePath + "/" + chatService!!.BeamBask + "/" + chatService!!.DataBase + "/Chat").mkdirs()
File(ctx.applicationContext.filesDir.absolutePath + "/" + chatService!!.BeamBask + "/" + chatService!!.Friends).mkdirs()
val KEY_PICTURE_AVATAR = result.get("avatar").asString
val KEY_PICTURE_AVATAR_THUMBS = result.get("avatar_thumbs").asString
if (Build.VERSION.SDK_INT >= 23) {
val folder = File(Environment.getExternalStorageDirectory().toString() + "/" + chatService.BeamBask + "/" + chatService.DataBase + "/")
if (folder.exists() && folder.canRead()) {
val picture = File(Environment.getExternalStorageDirectory().toString() + "/" + chatService.BeamBask + "/" + chatService.DataBase + "/" + number_phone!!.replace("+", "") + ".jpg")
if (picture.exists()) {
picture.delete()
picture.createNewFile()
copy(picture_file,picture)
} else {
val picture_ = File(ctx.applicationContext.filesDir.absolutePath + "/" + chatService.BeamBask + "/" + chatService.DataBase + "/" + number_phone!!.replace("+", "") + ".jpg")
if (picture_.exists()) {
picture_.delete()
picture_.createNewFile()
copy(picture_file,picture_)
} else {
picture_.createNewFile()
copy(picture_file,picture_)
}
}
} else {
val picture_ = File(ctx.applicationContext.filesDir.absolutePath + "/" + chatService.BeamBask + "/" + chatService.DataBase + "/" + number_phone!!.replace("+", "") + ".jpg")
if (picture_.exists()) {
picture_.delete()
picture_.createNewFile()
copy(picture_file,picture_)
} else {
picture_.createNewFile()
copy(picture_file,picture_)
}
}
} else {
val picture = File(ctx.filesDir.absolutePath.toString() + "/" + chatService.BeamBask + "/" + chatService.DataBase + "/" + number_phone!!.replace("+", "") + ".jpg")
if (picture.exists()) {
picture.delete()
picture.createNewFile()
} else {
picture.createNewFile()
copy(picture_file,picture)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment