feat: Enhance file upload logging and error handling in TransportManager and ChatViewModel
This commit is contained in:
@@ -88,17 +88,22 @@ object TransportManager {
|
||||
val server = getActiveServer()
|
||||
|
||||
Log.d(TAG, "📤 Uploading file: $id to $server")
|
||||
Log.d(TAG, "📤 Content length: ${content.length}, first 50 chars: ${content.take(50)}")
|
||||
|
||||
// Добавляем в список загрузок
|
||||
_uploading.value = _uploading.value + TransportState(id, 0)
|
||||
|
||||
try {
|
||||
// 🔥 КРИТИЧНО: Преобразуем строку в байты (как desktop делает new Blob([content]))
|
||||
val contentBytes = content.toByteArray(Charsets.UTF_8)
|
||||
Log.d(TAG, "📤 Content bytes length: ${contentBytes.size}")
|
||||
|
||||
val requestBody = MultipartBody.Builder()
|
||||
.setType(MultipartBody.FORM)
|
||||
.addFormDataPart(
|
||||
"file",
|
||||
id,
|
||||
content.toRequestBody("application/octet-stream".toMediaType())
|
||||
contentBytes.toRequestBody("application/octet-stream".toMediaType())
|
||||
)
|
||||
.build()
|
||||
|
||||
@@ -110,6 +115,8 @@ object TransportManager {
|
||||
val response = suspendCoroutine<Response> { cont ->
|
||||
client.newCall(request).enqueue(object : Callback {
|
||||
override fun onFailure(call: Call, e: IOException) {
|
||||
Log.e(TAG, "❌ Upload failed for $id: ${e.message}")
|
||||
Log.e(TAG, "❌ Stack trace: ${e.stackTraceToString()}")
|
||||
cont.resumeWithException(e)
|
||||
}
|
||||
|
||||
@@ -120,12 +127,16 @@ object TransportManager {
|
||||
}
|
||||
|
||||
if (!response.isSuccessful) {
|
||||
val errorBody = response.body?.string() ?: "No error body"
|
||||
Log.e(TAG, "❌ Upload failed: ${response.code}, body: $errorBody")
|
||||
throw IOException("Upload failed: ${response.code}")
|
||||
}
|
||||
|
||||
val responseBody = response.body?.string()
|
||||
?: throw IOException("Empty response")
|
||||
|
||||
Log.d(TAG, "📤 Response body: $responseBody")
|
||||
|
||||
// Parse JSON response to get tag
|
||||
val tag = org.json.JSONObject(responseBody).getString("t")
|
||||
|
||||
|
||||
@@ -1934,9 +1934,14 @@ class ChatViewModel(application: Application) : AndroidViewModel(application) {
|
||||
var uploadTag = ""
|
||||
|
||||
if (!isSavedMessages) {
|
||||
Log.d(TAG, "👤 📤 Uploading avatar to Transport Server...")
|
||||
uploadTag = TransportManager.uploadFile(avatarAttachmentId, encryptedAvatarBlob)
|
||||
Log.d(TAG, "👤 📤 Upload complete, tag: $uploadTag")
|
||||
try {
|
||||
Log.d(TAG, "👤 📤 Uploading avatar to Transport Server...")
|
||||
uploadTag = TransportManager.uploadFile(avatarAttachmentId, encryptedAvatarBlob)
|
||||
Log.d(TAG, "👤 📤 Upload complete, tag: $uploadTag")
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "👤 ❌ Failed to upload avatar to Transport Server", e)
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
// Preview содержит tag::blurhash (как в desktop)
|
||||
|
||||
Reference in New Issue
Block a user