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

uploads folder is full of trash files #261

Closed
nanohard opened this issue Jul 30, 2018 · 5 comments
Closed

uploads folder is full of trash files #261

nanohard opened this issue Jul 30, 2018 · 5 comments

Comments

@nanohard
Copy link
Contributor

nanohard commented Jul 30, 2018

Whenever I create a content item I get an empty file in the uploads folder.
Why does this happen?
Is it possible to prevent this from happening so that only files > 0 bytes are put there?

Edit:
I have discovered that the filenames are timestamps. But why do they exists?

@nilslice
Copy link
Contributor

Hey, it is definitely possible but would require a patch that I have not had time to PR.

I'm not at my computer at the moment, but if you're interested in looking there's an upload.go file (I believe) where you'd likely check the byte length of the multipart fields and ignore anything that is == 0.

I would like to change the API a bit before v1 so that only multipart encoded form requests even go down the path of an upload and enable create/update requests to be in any other encoding. That would be an awesome PR if you are interested...

@nanohard
Copy link
Contributor Author

nanohard commented Jul 30, 2018

I could only implement a workaround to not show the zero-byte files in the GUI. I could not figure out how to get the files to not be created.

I think in order to do this several functions will have to be split up. As it stands now, it seems like the functions in question will only write to the database if the file is created. So- no file, no database entry.

This means that content cannot be created without a timestamped file being created first, which needs to be split out of the functions and made to be a separate, optional, operation.

Edit:
The reason content creation creates an empty file is in the case of adding a file to content. When a file is attached to content, the file is named [timestamp]-[filename].
When no file is attached to content, the file is named [timestamp]-, with just a dash at the end.
The easiest thing to do then, although sloppy, would be to see if the last character of the file is a dash (-) and then delete the file after creation when creating/editing content.

Ideally though, these functions would be rewritten.

@nanohard
Copy link
Contributor Author

nanohard commented Jul 30, 2018

Files and functions that are involved:

  • system/admin/handlers.go
    • editHandler() (calls on storeFiles() 1 time)
    • editUploadHandler() (calls on storeFiles() 3 times)
  • system/admin/upload/upload.go
    • storeFiles()

Perhaps, if storeFiles() is aptly named, then we can then just focus on editHandler() and editUploadHandler() and split out the calls to storeFiles() to call on only if actually storing a file. I'll have to actually read the code and see if storeFiles() triggers a database call. The file upload and save to database need to be mutually exclusive.

@olliephillips
Copy link
Contributor

Thought I would take a look at this, but I can not replicate this behaviour. Fixed already? Anyone else see empty files created? I see folders, but not files.

@olliephillips
Copy link
Contributor

Closing this on the basis that it is now old and I could not replicate - either with file or filerepeater. It may have been addressed. Please re-open if anyone finds this to still be an issue.

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