Skip to content

Issue with CLIPDROP API Image Download in Android App #25

@Gourav19961996

Description

@Gourav19961996

Hi Team,
I am currently using the ClipDrop APIs in my Android application, and I am facing issues with processing the image bytes I receive in the response. I have tried various methods including decoding the bytes into a bitmap and downloading the image via InputStream, but none of them have been successful in generating a usable output image.

When attempting to decode the image bytes into a bitmap using the following code snippet:
val imageInputStream = it.value.body()?.byteStream()
val imageBytes = imageInputStream?.readBytes()
val bitmapImage = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.size, null)
The bitmapImage is resulting in null.

Similarly, when I download the image using an InputStream and save it, the downloaded image is corrupted and not viewable on the device.
private fun saveImageAndPreviewOutput(inputStream: InputStream) {
try {
val directory = File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM), "photoLens")
if (!directory.exists()) {
directory.mkdirs()
}
val imageFile = File(directory, "${getUuid()}.png")
FileOutputStream(imageFile).use { output ->
inputStream.copyTo(output)
}
viewModel.outputImagePath = imageFile.toString()
val bundle = Bundle()
outputImageFragment.arguments = bundle
val transaction =
requireActivity().supportFragmentManager.beginTransaction()
.addToBackStack("OutputImageFragment")
.add(R.id.flCameraFragment, outputImageFragment)
transaction.commit()
} finally {
inputStream.close()
}
}

The downloaded image is not opening on the device, and it seems to be corrupted.

Could you please assist me in identifying and resolving the issue? I have attached a sample of the downloaded image for reference.

I have followed the example provided on the GitHub repository for the Android integration, but I am encountering the same issue there as well.

Thanks and regards,
Gourav
+91-9625508164
gouravdhankher1996@gmail.com

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions