We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation .
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Yes.
This issue occurs randomly with some uploaded images i.e. it does not occur with every uploaded image so have not been able to reproduce but have faced it in production.
Have also noticed that the size of all such corrupted images have size as multiple of 256 KB (for example 512 KB, 1536 KB etc.)
General steps :
package com.example.services import android.app.Service import android.content.Intent import android.net.Uri import android.os.IBinder import android.util.Log import com.google.firebase.storage.FirebaseStorage import com.google.firebase.storage.StorageMetadata import com.google.firebase.storage.StorageReference import java.io.File class MyService : Service () { private var storage : FirebaseStorage ? = null private var storageReference : StorageReference ? = null override fun onBind ( intent : Intent ? ): IBinder ? { return null } override fun onStartCommand ( intent : Intent ? , flags : Int , startId : Int ): Int { // Initialize Firebase storage storage = FirebaseStorage .getInstance() storageReference = storage !! .reference // Dummy list of image URIs val imageList = listOf ( " uri1 " , " uri2 " , " uri3 " ) // Upload images to Firebase if (imageList.isNotEmpty()) { uploadImages(imageList) } return START_STICKY } private fun uploadImages ( imageList : List < String >) { imageList.forEach { uri -> val fileUri : Uri = Uri .parse( " file:// $uri " ) // Set metadata for the uploaded image val metadata = StorageMetadata . Builder () .setContentType( " image/jpeg " ) // Add custom metadata as needed // Upload image to Firebase Storage val uploadTask = storageReference?.child(uri)?.putFile(fileUri, metadata.build()) // Handle upload success, failure, and progress uploadTask?.addOnSuccessListener { taskSnapshot -> // Handle successful upload // You can get the download URL if needed: val downloadUrl = taskSnapshot.metadata?.reference?.downloadUrl Log .i( " MyService " , " Image uploaded successfully " ) // Remove the uploaded image from local storage removeImageFromLocalStorage(uri) }?.addOnFailureListener { exception -> // Handle failed upload Log .e( " MyService " , " Image upload failed: ${exception.message} " ) }?.addOnProgressListener { progress -> // Handle upload progress val progressPercent = 100.0 * progress.bytesTransferred / progress.totalByteCount Log .i( " MyService " , " Upload progress: $progressPercent % " ) } } } private fun removeImageFromLocalStorage ( uri : String ) { val file = File (uri) if (file.exists()) { val isDeleted = file.delete() Log .d( " MyService " , " Deleted image from local storage: $isDeleted " ) } } override fun onDestroy () { super .onDestroy() } }
The text was updated successfully, but these errors were encountered:
Hi ,thank you for reaching out. I tried reproducing the issue but I was unable to encounter the behavior. I used the code you shared and uploaded images with the size of more than 1MB and all images were uploaded without an issue.
Are you constantly experiencing this error or does the issue occur on certain devices and/or android versions? I’m thinking if network or device resource allocation is a factor to the issue.
Could you try reproducing the issue using our quickstart app? Aside from that, have you tried using a work manager to manage the upload task?
Sorry, something went wrong.
Hi @lehcar09 , thankyou for looking into the issue.
These are received randomly, 1 out of say 100 images comes out as corrupted, as for devices, mostly have observed in Galaxy A53 5G (Android 14) but have gotten on some other devices as well.
Could you tell me why network or resource allocation would be a factor here? And how I could look into that?
Also the corrupted images always have a size i.e. a multiple of 256 KB, was thinking if that has something to do with firebase chunk size?
As for reproducing it, I have never been able to reproduce it either, only received corrupted images from users, will look into work manager though, would that help fix the issue you think?
Attaching a corrupted image for reference :
Hi @lehcar09 , could you provide some info on the above questions? Would help debug the issue on my end, thanks!
No branches or pull requests