matrix-org / matrix-org/matrix-android-sdk2-sample

send video in room return 413 Payload Too Large

Open
#17 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Kotlin
Stars
26
Forks
12
PR merge metrics
No merged PRs in 30d

Description

with this code i try to send vide :

private fun setVideoMessage(uri: Uri, file: DocumentFile?) {
val uploadStateTracker = DefaultContentUploadStateTracker()

uploadStateTracker.track("video_upload", object : ContentUploadStateTracker.UpdateListener {
override fun onUpdate(state: ContentUploadStateTracker.State) {
when (state) {
is ContentUploadStateTracker.State.Idle -> {
Log.d("UploadStateTracker", "Idle state")
}

is ContentUploadStateTracker.State.EncryptingThumbnail -> {
Log.d("UploadStateTracker", "Encrypting thumbnail")
}

is ContentUploadStateTracker.State.CompressingImage -> {
Log.d("UploadStateTracker", "Compressing image")
}

is ContentUploadStateTracker.State.CompressingVideo -> {
val percent = state.percent
Log.d("UploadStateTracker", "Compressing video: $percent%")
}

is ContentUploadStateTracker.State.UploadingThumbnail -> {
val current = state.current
val total = state.total
Log.d("UploadStateTracker", "Uploading thumbnail: $current/$total")
}

is ContentUploadStateTracker.State.Encrypting -> {
val current = state.current
val total = state.total
Log.d("UploadStateTracker", "Encrypting video: $current/$total")
}

is ContentUploadStateTracker.State.Uploading -> {
val current = state.current
val total = state.total
Log.d("UploadStateTracker", "Uploading video: $current/$total")

// Calculate progress percentage
val progressPercentage = (current.toFloat() / total.toFloat()) * 100

// Update the progress in your UI
Log.d(
"UploadStateTracker",
"Uploading video: progressPercentage : $progressPercentage"
)
}

is ContentUploadStateTracker.State.Success -> {
Log.d("UploadStateTracker", "Upload completed successfully")

// Prepare the content data
val content = prepareContentData(uri)

// Send the content using the sendMedia method
room?.sendService()?.sendMedia(
content,
compressBeforeSending = false,
roomIds = setOf(roomId)
)

// Clear the upload state tracker
uploadStateTracker.clear()
}

is ContentUploadStateTracker.State.Failure -> {
val throwable = state.throwable
Log.e("UploadStateTracker", "Upload failed: ${throwable.message}")
// Clear the upload state tracker
uploadStateTracker.clear()
}
}
}
})
lifecycleScope.launch {
try {
showSnackBar("Uploading Video, please wait...")
val fileSize: Long = file!!.length()

// Update the state when necessary
uploadStateTracker.updateState(
ContentUploadStateTracker.State.Uploading(
0,
fileSize
)
)

// Simulate video upload progress
val bufferSize = 1024
val buffer = ByteArray(bufferSize)
var current: Long = 0

contentResolver.openInputStream(uri)?.use { inputStream ->
var bytesRead = inputStream.read(buffer)
while (bytesRead != -1) {
// Update the state with the current progress
current += bytesRead
uploadStateTracker.updateState(
ContentUploadStateTracker.State.Uploading(
current,
fileSize
)
)

bytesRead = inputStream.read(buffer)
}
}

// Update the state to indicate a successful upload
uploadStateTracker.updateState(ContentUploadStateTracker.State.Success)
} catch (failure: Throwable) {
Log.e("UploadStateTracker", "Upload failed: $failure")

// Update the state with the failure
uploadStateTracker.updateState(ContentUploadStateTracker.State.Failure(failure))
} catch (failure: Exception) {
Log.e("UploadStateTracker", "Upload failed: $failure")

// Update the state with the failure
uploadStateTracker.updateState(ContentUploadStateTracker.State.Failure(failure))
}
}

}
the file size is 15MB and server max upload size is 50MB but i get this error :

<-- 413 Payload Too Large https://im.encrym.com/_matrix/media/r0/upload (14986ms, unknown-length body)
2023-06-07 14:29:01.955 24505-24748 W The error returned by the server is not a MatrixError
2023-06-07 14:29:01.960 24505-24748 E ## ERROR java.lang.RuntimeException: HTTP 413:
2023-06-07 14:29:01.960 24505-24748 E 413 Request Entity Too Large
2023-06-07 14:29:01.960 24505-24748 E
2023-06-07 14:29:01.960 24505-24748 E

413 Request Entity Too Large


2023-06-07 14:29:01.960 24505-24748 E
nginx
2023-06-07 14:29:01.960 24505-24748 E (function(){var js =

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at setVideoMessage and the sendMedia call, then trace the upload request to /_matrix/media/r0/upload. Compare the request size and server or nginx limits with the reported 15 MB file and 413 response. Done means identifying the limiting layer and confirming whether the upload succeeds within the stated 50 MB limit.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
api, mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.