0

I am attempting to upload a zip file to Firebase storage. The zip file is located in the documents directory for my app.

I create the reference and use putFile to start the upload

let storageReference = ORBFirestore.getStorage()
        .reference(withPath: "users/")
        .child("\(userId)/\(sensorZippedFolder.lastPathComponent)")

let uploadTask = storageReference.putFile(from: sensorZippedFolder,
                                              metadata: self.remoteStorageMetaData)

The file url looks like this:

file:///var/mobile/Containers/Data/Application/861A23DF-EF32-4458-AA9D-C3F94BB1A4F8/Documents/Session_AmOH6ME627mVbOeIdVIT.zip

Observing the progress I can see that it reaches 100% and then throws an error.

The error I receive looks like this:

Failed to upload zip to remote storage: FirebaseStorage.StorageError.unknown(message: "Unexpected 40 code from backend", serverError: ["NSErrorPeerAddressKey": <1c1e01bb 00000000 2a001450 400b0c02 00000000 0000005f 00000000>, "_NSURLErrorRelatedURLSessionTaskErrorKey": <__NSArrayI 0x10fe5e020>( BackgroundUploadTask .<1>, LocalUploadTask .<1> ) , "_kCFStreamErrorCodeKey": 40, "_NSURLErrorFailingURLSessionTaskErrorKey": BackgroundUploadTask .<1>, "_kCFStreamErrorDomainKey": 1, "ResponseErrorDomain": "NSPOSIXErrorDomain", "ResponseErrorCode": 40, "bucket": "orb-storage-01-dev-us", "NSUnderlyingError": Error Domain=NSPOSIXErrorDomain Code=40 "Message too long" UserInfo={_NSURLErrorFailingURLSessionTaskErrorKey=BackgroundUploadTask .<1>, _kCFStreamErrorDomainKey=1, NSErrorPeerAddressKey={length = 28, bytes = 0x1c1e01bb 00000000 2a001450 400b0c02 ... 0000005f 00000000 }, _kCFStreamErrorCodeKey=40, _NSURLErrorRelatedURLSessionTaskErrorKey=( "BackgroundUploadTask .<1>", "LocalUploadTask .<1>" )}, "object": "users/IeQFdqCmT9Xncfo2zNf2iugd7Yp2/Session_AmOH6ME627mVbOeIdVIT.zip"])

I don't understand the error "Message too long" ?

Any help would be greatly appreciated thank you

  • I have tried to force the upload to happen on the Main thread
  • I have tried to move or copy the zip somewhere else
  • I have tried putData

What I see has worked is trying again and again. Eventually after X tries it works. Why does it work sometimes but not all the time ?

2
  • 1
    The error indicates that the problem is on the backend. It isn't anything in your code. Google suggests that "Message too long" can be an intermittent problem on the GCP side. Commented Jun 4 at 22:20
  • @Paulw11, thank you. Commented Jun 5 at 9:01

1 Answer 1

0

use putData instead of putFile, mappedIfSafe is important for big files not to fully load into memory

let data = try Data(contentsOf: localFile, options: .mappedIfSafe)
self.uploadTask = riversRef2.putData(data, metadata: metadata) { ... }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.