tus / tus/TUSKit

couldNotUploadFile Error with status code 409: Upload-Offset conflict

Open
#162 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Swift
Stars
245
Forks
128
PR merge metrics
No merged PRs in 30d

Description

I'm using TUSKit with Supabase storage (an S3 wrapper), and for the most part it's working fine except the case where I try to upload a large file (~1gb) while repeatedly backgrounding and foregrounding the app on my phone, either by swiping to the Home Screen or locking my phone. It's inconsistent, but after a few times doing that I get a couldNotUploadFile error with an underlying 409 status code error, and digging into the upload method in TUSAPI and printing the raw response data, it says "Upload-Offset conflict".

How can I debug this? Is it an issue with my usage of TUS, the TUSKit iOS SDK itself, or is it possible this is a problem with Supabase's TUS protocol implementation?

Here's the full error:

uploadFailed: couldNotUploadFile(underlyingError: TUSKit.TUSAPIError.failedRequest(<NSHTTPURLResponse: 0x28347f300> { URL: <url> } { Status Code: 409, Headers {
    "Access-Control-Allow-Origin" =     (
        "*"
    );
    "Alt-Svc" =     (
        "h3=\":443\"; ma=86400"
    );
    "Content-Length" =     (
        23
    );
    Date =     (
        "Wed, 31 May 2023 16:14:12 GMT"
    );
    Server =     (
        cloudflare
    );
    "Strict-Transport-Security" =     (
        "max-age=2592000; includeSubDomains"
    );
    Vary =     (
        "Accept-Encoding"
    );
    "access-control-expose-headers" =     (
        "Authorization, Content-Type, Location, Tus-Extension, Tus-Max-Size, Tus-Resumable, Tus-Version, Upload-Concat, Upload-Defer-Length, Upload-Length, Upload-Metadata, Upload-Offset, X-HTTP-Method-Override, X-Requested-With, X-Forwarded-Host, X-Forwarded-Proto, Forwarded, Upload-Expires"
    );
    "cf-cache-status" =     (
        DYNAMIC
    );
    "cf-ray" =     (
        "7d0082268c553344-EWR"
    );
    "sb-gateway-mode" =     (
        direct
    );
    "sb-gateway-version" =     (
        1
    );
    "tus-resumable" =     (
        "1.0.0"
    );
} }))

Here's how I'm using TUS:

let tusEndpoint = Environment.SUPABASE_URL.appendingPathComponent("storage/v1/upload/resumable")

self.tusClient = try TUSClient(
    server: tusEndpoint,
    sessionIdentifier: "media-upload-queue",
    chunkSize: 6 * 1024 * 1024
)
let context: [String : String] = {
  var context: [String : String] = [:]
  
  if let mimeType = self.mimeType(forFile: fileURL) {
      context["contentType"] = mimeType
  }
  
  context["bucketName"] = <bucketName
  context["objectName"] = <fileName>
  
  return context
}()

let headers: [String : String] = {
  var headers: [String : String] = [:]
  
  headers["authorization"] = "Bearer <token>"
  headers["x-upsert"] = "true"
  
  return headers
}()

try self.tusClient.uploadFileAt(
  filePath: fileURL,
  customHeaders: headers,
  context: context
)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the TUSKit.TUSAPI upload method and the Supabase resumable-upload endpoint shown in the report. Reproduce the large-file upload while repeatedly backgrounding and foregrounding the phone, inspect the raw 409 response and Upload-Offset values, and determine whether the conflict originates in TUSKit usage or Supabase's implementation.

Written by the indexing model from the issue text.

Assessment

Tech stack
supabase, swift
Domain
api, mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.