Dmitriy Malayev
09/18/2023, 5:55 PMHello. I am trying to implement a progress bar when a user tries to download a report and I'm getting errors
suspend fun downloadReportSection(
reportFileName: String,
section: EsgSection? = null,
progressCallback: (Int) -> Unit
): ByteArray? {
return try {
val response = httpClient.get("${BackendReportingServiceURL}/esg-report/preview-report") {
parameter("reportFileName", reportFileName)
section?.let { parameter("section", it.name) }
onUpload { bytesSentTotal, contentLength ->
val progressPercentage = ((bytesSentTotal / contentLength.toDouble()) * 100).toInt()
progressCallback(progressPercentage)
}
}
if (response.status == HttpStatusCode.OK) {
progressCallback(100) // 100% completion once done
return response.readBytes()
} else {
null
}
} catch (e: Exception) {
console.log("Error: ${e.message}")
null
}
}
Box {
Button {
variant = ButtonVariant.contained
onClick = {
mainScope.launch {
val pdfReport = downloadReportSection(
props.esgReportStateProps.reportFileName,
EsgSection.General,
progressCallback = {}
)
pdfReport?.let {
val blob = Blob(arrayOf(it), BlobPropertyBag("application/pdf"))
val url = URL.createObjectURL(blob)
val a = document.createElement("a") as HTMLAnchorElement
a.href = url
a.download = props.reportStateProps.reportFileName
a.click()
}
}
}
+"Preview"
}
}
Could not load content for /kotlinx-coroutines-core/js/src/internal/CoroutineExceptionHandlerImpl.kt?6a41 (Fetch through target failed: Unsupported URL scheme; Fallback: HTTP error: status code 404, net::ERR_UNKNOWN_URL_SCHEME)
Error_0 {message: 'Fail to fetch', cause: TypeError: Failed to execute 'fetch' on 'Window': Request with GET/HEAD method cannot have body.
Joffrey
09/23/2023, 10:28 AMBackendReportingServiceURL
. The error says the URL scheme is unsupported, or maybe this variable is just completely empty.