tus / TUSKit

The tus client for iOS.

Home Page:https://tus.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Example Project: Missing Extensions for Images and Error for File Uploads

denizbinay opened this issue · comments

Environment

  • Device: iPad Mini 6th Generation
  • OS: iPadOS 17.4.1
  • Xcode Version: 15.3
  • TUS iOS Client Version: 3.3
  • TUS Server: Official TUS Demo Server and ankitpokhrel/tus-php

Issue Description

I am facing two issues when trying out the example project for uploads:

  1. Images Losing Extensions: Uploading images via the "Upload Image" option results in the images losing their extensions and being named after the UUID of the upload. This issue is consistent across both the official TUS demo server and a self-hosted PHP TUS server. The images seem to be corrupted and lack any extension when downloaded.

  2. Error When Uploading Files: Selecting the "Upload File" option leads to an immediate error without a successful upload:

The view service did terminate with error: Error Domain=_UIViewServiceErrorDomain Code=1 "(null)" UserInfo={Terminated=disconnect method}

Steps to Reproduce

  1. Deploy the Example Project on an iPad Mini 6th Gen running iPadOS 17.4.1, using Xcode 15.3.
  2. Attempt uploads to either the official TUS demo server or a self-hosted PHP server.
  3. Use the "Upload Image" feature to upload an image.
  4. Use the "Upload File" feature to attempt a file upload.
  5. Attempt to download the uploaded image.

Expected Behavior

  • Images should upload correctly, maintaining their original filenames and extensions, and should not appear corrupted upon download.
  • Files should upload successfully without triggering any error messages.

Actual Behavior

  • Images uploaded lose their extensions and are named using the UUID. These downloaded images appear to be corrupted and without an extension.
  • Attempting file uploads results in an error message and no successful upload.

Additional Context

  • I am fairly new to Swift/TUS, and I haven't made any changes to the example project provided.
  • The JavaScript client and the PHP server have previously worked well for me.

I am seeking assistance or clarification on whether these are problems with the TUS iOS client or if I might have overlooked something in my setup process.

Hi Deniz, I will take a look at this in the next day or two, thanks for filing this issue.

It's certainly interesting that you're seeing these issues because in the past the example app has been able to perform uploads for images (as well as being able to download them) perfectly fine. Wonder if something in iOS has changed since we've last tested.

  1. Images Losing Extensions: Uploading images via the "Upload Image" option results in the images losing their extensions and being named after the UUID of the upload. This issue is consistent across both the official TUS demo server and a self-hosted PHP TUS server. The images seem to be corrupted and lack any extension when downloaded.

tusd (which powers the demo server) only preserves the file name and type of the filename and filetype meta data values are set. This is not a requirement by the tus protocol, so other servers might not implement this. If this information is missing, tusd will serve the file without its original extension because the client didn't transmit this information.

@Acconut, are you sure that is the reason for this? AFAIK, the Upload-Metadata is transmitted with the needed fields: filetype and filename. But in my case with some default MIME type, and the filename is already the UUID without an extension.

As I said, I'm new to Swift, but it seems to me that in the makeUploadMetaHeader(), the metaData.filePath.lastPathComponent is already called on a copy of the original file that has no extension and a UUID as its name.

@Acconut is correct, the sample app does not correctly transfer the file type for files that are picked through the file picker in the sample app.

I'm currently working on figuring out whether this is a bug in the sample app or in TUSKit and I'll report back here once I know. Just wanted to leave this here in the meantime.

Ps. the downloaded files are not corrupted; re-adding their extension results in working images for me.

This issue should be resolved by #186

The sample app uploads data directly but wasn't providing file extensions for said data. This is fixed with the linked PR. Let me know whether that works for you and I'll merge it into main

Hi @donnywals , thank you very much! With these changes, the file extension is preserved. However, it's still renamed to the UUID. Is this the desired behavior? I would suggest that the file should preserve its original name as well. What do you think?

That's true. I know this behavior is intentional due to having to have unique file names locally (we have to copy every file that's uploaded into a directory that we own to upload it correctly.)

I'll need to see whether we could preserve the original file name as metadata and send that to the backend. And then also whether that would break anything later on.

I'll treat that as a separate issue for the purposes of my PR since the missing extension can be fixed in the sample app itself and making a change like your suggesting here would require a change in the SDK

So I just did some more thinking on this, and the way the sample app is implemented is by calling the upload data method rather than upload URL. When you'd use upload URL, the filename would be preserved.

We could add an overload to the singular upload data method but the one that takes an array would be trickier since we'd have to support uploading tuples of (Data, String) rather than data objects like we do now.

That said, I think the most reasonable approach here could be to copy data to some URL that's owned by the app and then asking TUSKit to upload those URLs instead of following the sample app's approach of uploading Data