Skip to content
New issue

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

Missing File Extensions #60

Closed
ScarlettCode opened this issue Apr 17, 2019 · 6 comments
Closed

Missing File Extensions #60

ScarlettCode opened this issue Apr 17, 2019 · 6 comments

Comments

@ScarlettCode
Copy link

ScarlettCode commented Apr 17, 2019

Hi,

Not sure if this is by design or if I'm doing something wrong but none of my uploaded images have file extensions once saved. Any ideas?

If I force it to open it opens the image fine so it's saving all the data just giving it a name without an extension
image

Thanks

@smatsson
Copy link
Collaborator

Hi,

It's by design in the protocol. Metadata is not part of the specification and is up to the server and client to negotiate. You need to provide filename/extension as metadata and use that when reading the file.

Here is an example of the filename and content type being sent as metadata:
https://github.com/tusdotnet/tusdotnet/blob/master/Source/TestSites/AspNetCore_netcoreapp2.2_TestApp/wwwroot/index.html#L90

And here is how you would use it:
https://github.com/tusdotnet/tusdotnet/blob/master/Source/TestSites/AspNetCore_netcoreapp2.2_TestApp/Middleware/SimpleDownloadMiddleware.cs#L46

@ScarlettCode
Copy link
Author

Hi,

It's a bit strange to have files saved without their extension and then to only add the extension when reading the file. Not possible to give the file an extension when saving based on the metadata? Having files and meta data in different places is weird but if that's how the protocol is setup I'll use it as such.

Thank you

@smatsson
Copy link
Collaborator

Once again, metadata such as file extension is not part of the protocol and must be negotiated between the server and the client. Since metadata can be whatever there is no way for tusdotnet to know what the extension is and name the file accordingly.

What are you trying to achieve? There is nothing preventing you from renaming the file on disk on e.g. OnFileCompleteAsync using the metadata provided by your clients.

@ScarlettCode
Copy link
Author

Oh I see so just the transfer protocol doesn't include metadata but once you have the file you can do what you want. Got it. Thanks!

@ronkristoff
Copy link

Hi I was able to change the name of the uploaded file. I just called the File.Copy onFileCompleteAsync, but my problem is when deleting the old file, it throws exception that the file is still being used.

try
{

            File.Copy(sourceFile, test);
            File.Delete(sourceFile);
        }
        catch (Exception ex)
        {

            throw;
        }

@smatsson
Copy link
Collaborator

smatsson commented Aug 9, 2021

@ronkristoff That the file is being used usually indicates that you did not dispose of the file stream after using it. Also why would you copy potentially gigabytes of data instead of just renaming the file or at the very least move it?

This is a very old issue and a better solution is probably to use a custom id provider to change the id to contain the extension to avoid mucking about with the file afterwards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants