firebase / firebase-ios-sdk

Firebase SDK for Apple App Development
https://firebase.google.com
Apache License 2.0
5.6k stars 1.47k forks source link

Uploading to Storage fails with "Code=-13000 "An unknown error occurred, please check the server response." #8105

Closed HauntedSoul closed 3 years ago

HauntedSoul commented 3 years ago

[REQUIRED] Step 1: Describe your environment

[REQUIRED] Step 2: Describe the problem

I'm implementing a video upload function that picks a video from the media library, writes it to a temp local file and finally uploads it to Storage. The first attempt after each app startup works fine, the second upload of a different file fails with an error similar to:

Error Domain=FIRStorageErrorDomain Code=-13000 "An unknown error occurred, please check the server response." UserInfo={object=coaches/cat/cat-tky6BL.mp4, ResponseBody=Can not finalize upload. Current size is 10457692. Expected final size is 3865459., bucket=dev-eastnine.appspot.com, data={length = 84, bytes = 0x43616e20 6e6f7420 66696e61 6c697a65 ... 33383635 3435392e }, data_content_type=text/plain; charset=utf-8, NSLocalizedDescription=An unknown error occurred, please check the server response., ResponseErrorDomain=com.google.HTTPStatus, ResponseErrorCode=400}

Uploading the same video from a new local file also succeeds (because it matches the size?). It feels like there is some kind of caching going on that saves the first file size and checks each following file against that. Possibly because I'm sending the URL, but the file is different.

A symptom of this issue I also detect is that the progress listener if the second file if larger than the first goes over 1.0 up to whatever factor the file size is over the first until it fails with the error above.

Steps to reproduce:

Simply try to upload different video files to different references but from the same local URL.

Relevant Code:

private func uploadLocalVideo() {
    guard let user = UserModel.currentUser, let coachId = user.coachId else { return }

    let metadata = StorageMetadata()
    metadata.contentType = "video/mp4"
    metadata.customMetadata = ["userId":user.documentID, "coachId":coachId, "contentId":contentData.contentId]

    let storage = Storage.storage().reference()
    let ref = storage.child("coaches").child(coachId).child(contentData.contentId + ".mp4")
    DispatchQueue.main.async {
        self.videoUploadTask = ref.putFile(from: NewWorkoutManager.videoUrl, metadata: metadata) { (metadata, error) in
            if let error = error {
                print("********** Error: \(error)")
            } else {
                self.videoUploaded = true
            }
            if let metadata = metadata {
                print("******** Uploaded Video to \(metadata.path)")
            }
        }
    }
}
rizafran commented 3 years ago

Hi @HauntedSoul, it seems like your issue is related to #6720. Also, can you provide a sample project that will reproduce the issue in order to help with the investigation? Thanks.

HauntedSoul commented 3 years ago

Yes the issue looks related to the linked one. I won't be able to create a sample project in the short term. I can add that I have fixed the issue by using a URL created in the scope of the function above instead of trying to use the one that was defined in a constant.

rizafran commented 3 years ago

Thanks for sharing your findings, @HauntedSoul. It seems that the issue has been fixed by updating the URL. I'll close this issue for now, but we can re-open when we get more reports.