Gitea: Cannot upload file of this type to a release (zip)

Created on 17 Jan 2019  路  30Comments  路  Source: go-gitea/gitea

  • Gitea version (or commit ref): 1.6.3, 1.7.0, 1.7.1
  • Git version: 2.20.1
  • Operating system: Windows 10 x64
  • Database (use [x]):

    • [ ] PostgreSQL

    • [ ] MySQL

    • [ ] MSSQL

    • [x] SQLite

  • Can you reproduce the bug at https://try.gitea.io:

    • [x] Yes (https://try.gitea.io/ve3/test/src/tag/0.1)

    • [ ] No

    • [ ] Not relevant

Description

I tried to upload a file to a release but got error message "You cannot upload files of this type".
The file is zip and its mime type is application/zip.

Here is app.ini configuration.

[attachment]
ENABLED = true
PATH = D:/my-work-spaces/gitea/data/attachments
ALLOWED_TYPES = application/zip|application/x-compressed-tar|application/x-gzip
MAX_SIZE = 20
MAX_FILES = 1
kinquestion revieweconfirmed

Most helpful comment

ALLOWED_TYPES = application/zip|application/x-zip|application/x-compressed-tar|application/x-compressed|application/x-gzip|application/x-compress|application/x-zip-compressed|multipart/x-zip

This is work for me. thanks.

All 30 comments

Have you restarted Gitea?

Have you restarted Gitea?

Yes, I did.

I have the very same issue.
Any suggestions?

Same here on latest 1.7.1, it won't let me upload zip files even though they are explicitly allowed.

Workaround: add application/x-zip-compressed to ALLOWED_TYPES

Hmm ok so if the data gets to Gitea it will definitely be assigned a mimetype of application/zip.

This mimetype is being assigned by your browser and is being checked in dropzone. Are you using internet explorer?

Unfortunately there's not much that can be done - I think you just have to add application/x-zip-compressed either that or we have to change dropzone upstream to have a list of mapping from old non valid mimetypes to real mimetypes.

I'm using Firefox.
Added application/zip|application/x-zip|application/x-zip-compressed|application/x-compress|application/x-compressed|multipart/x-zip (copied from https://filext.com/file-extension/ZIP ) but still does not work.

Of cause, I'm already restarted Gitea.

Gitea 1.7.0

Are you running Gitea behind an nginx proxy? If so you will need to allow nginx to allow it too

If you're not running an nginx proxy then I think this is something to do with your browser - I am really not sure that this is even getting to the Gitea server and I think your upload is being rejected by dropzone.

https://github.com/go-gitea/gitea/blob/801843b0115e29ba2304fa6a5bea1ae169a58e02/public/vendor/plugins/dropzone/dropzone.js#L1583

This is on your browser so you should be able to double check what it's seeing by sticking breakpoints in in the developer console.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 weeks. Thank you for your contributions.

I don't running nginx proxy. This problem even occur on https://try.gitea.io
As the link I provided https://try.gitea.io/ve3/test/src/tag/0.1

I'm not sure did you tried to upload .zip on your server ( https://try.gitea.io ) because it same and it is not just my browser problem.

This worked fine for me on try.gitea.io just now:

https://try.gitea.io/mrsdizzie/parsing-errors/releases

That sshot.zip attachment has a mime-type of application/zip same as mentioned in the issue report.

The link you've provided to try.gitea.io unfortunately doesn't help because of the nature of the problem (there is no file there for anybody to look at). Is it possible to share an example zip file that doesn't work right for you? Being able to reproduce will help track down what may be happening (can't reproduce it with my own application/zip file)

https://try.gitea.io/ve3/test/releases

Download (ZIP) from there
Edit release
Upload the zip file
Failed.

All the zip files cannot upload.

This seems to be only happens with Firefox on Windows (not sure Firefox on other os).

I was just able to download that zip file, edit the release in my example, and the upload it fine:

https://try.gitea.io/mrsdizzie/parsing-errors/releases

It works on Safari, Chrome, and Firefox on macOS.

Can't reproduce with any of the current suggest steps here on my end unfortunately :( Sounds like perhaps a Firefox on Windows bug.

Also FWIW some searching suggests this might be related to problems with the files Firefox uses to store mime-type information and starting over with a fresh profile seems to help many people having trouble uploading to different sites.

gitea 1.7.5 armv7
on raspbian stretch
Browser chromium on Linux Mint

I wanted to add an observation, because I was curious if there is nothing in the logs about blocked mime-types, so one could just easily add them gitea kindly detected.

ALLOWED_TYPES=application/zip

With this attaching zip files is possible on my installation. Then I did:
Modified app.ini: LEVEL = Trace && service gitea restart

After restart I tried to upload a tar.gz file, and to my surprise in gitea.log I got:
2019/04/05 20:55:27 [I] Attachment with type application/x-gzip blocked from upload

Easy enough, went ahead and added that mime type + restart of gitea.

ALLOWED_TYPES=application/zip|application/x-gzip

Uploading of tar.gz files still didn't work. So...long story short,
I never got a blocked entry in my logs after that again.

I restarted multiple times, reverted the ALLOWED_TYPES, changed ALLOWED_TYPES, changed LEVEL back and forth, logged in/out, changed user and multiple combinations of that. I never got a blocked entry in gitea.log again.

I've just encountered this infuriating bug as a user of the showcase instance gitea.com - I created an account there to try and get away from this kind of nonsense on Github!

From try.gitea.io server, I tried to upload fake .jpg file.
I created fake .jpg file with .txt file. (new > text file > rename fake-image.jpg).
I try to select a file > success, the file was sent to server via XHR but the response is failed. Error 400 with message:

File type is not allowed

This issue stuck at select a file and then failed. It is not even upload yet.

My browser (Firefox on Windows) have no problem with normal upload HTML form with PHP, ASP.net, or any other programming languages on earth.
They can detect the real file's mime type correctly.

So, this problem should be fixed easily if we skip the check mime type part that is currently using JS and let it check with the server instead.
The server already do that (check mime type), doing this with JS is not necessary.

Edit:
This also happens with MS Edge. ( https://stackoverflow.com/q/32849014/128761 ). I'm not sure that Firefox, IE, and Edge use the same mime type data source but they both cant get JS input files[0].type.

Here is the source code to test get file's mime type from browser input.

<form enctype="multipart/form-data">
<input type="file" multiple="multiple" class="dz-hidden-input" accept="image/jpeg,image/png,application/zip,application/gzip">
<button type="submit">Upload</button>
</form>

<div class="debug"></div>

<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script>
    $(document).ready(function() {
        $('.dz-hidden-input').on('change', function(e) {
            console.log(this.files[0].type);
            $('.debug').append('<br> - ' + this.files[0].type);
        });
    });
</script>

Failed: IE, Firefox, Edge

Easy enough, went ahead and added that mime type + restart of gitea.

ALLOWED_TYPES=application/zip|application/x-gzip

Uploading of tar.gz files still didn't work. So...long story short,
I never got a blocked entry in my logs after that again.

I did exactly that change on https://codeberg.org and it works there now :man_shrugging:

As I said, verify mime type using JS is based on browser and it is too much various causes (OS, browser, version on both OS & browser, etc).
Remove the JS mime type verification and let this task done by the server side to give it one standard.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 weeks. Thank you for your contributions.

I got today the same problem. I tried drag&drop and upload by clicking (file open dialogue).

My parameter are like this:

  • Gitea version: 1.9.1
  • Git version: 2.22.0.windows.1
  • Operating system: (PC A) Windows 7 + Vivaldi 2.6.1566.49 x64 / Firefox 68.0.2 (64-bit) on web version; (PC B) Windows 10 + Vivaldi 2.6.1566.49 x64 on local machine
  • Database (use [x]):

    • [ ] PostgreSQL

    • [ ] MySQL

    • [ ] MSSQL

    • [x] SQLite

  • Can you reproduce the bug at https://try.gitea.io:

    • [x] Yes (https://try.gitea.io/JAD-SVK/UploadTest/releases)

    • [ ] No

    • [ ] Not relevant

This setting helped for me:

[attachment]
ENABLED = true
PATH = ./data/attachments
ALLOWED_TYPES = application/zip|application/x-zip|application/x-compressed-tar|application/x-compressed|application/x-gzip|application/x-compress|application/x-zip-compressed|multipart/x-zip
MAX_SIZE = 20
MAX_FILES = 5

TestZipFile.zip

File: TestZipFile.txt
Content: This file is test file + new line (CR+LF)
Zipped using 7z version 19.00

For release, you should change repository.upload section not attachment

[repository.upload]
ALLOWED_TYPES = "application/zip|application/gzip|application/x-gzip|application/x-gtar|application/x-tgz|application/x-compressed-tar|text/plain"

[attachment]
ALLOWED_TYPES = "application/zip|application/gzip|application/x-gzip|application/x-gtar|application/x-tgz|application/x-compressed-tar|text/plain"

Please confirm @ve3 @JAD-SVK

I need to add (configure)

[attachment]
ALLOWED_TYPES = application/zip|application/x-zip-compressed

To be able to upload zip files (from Vivaldi and Firefox on Windows 7) to release. Both types need to be active.

No configuration in [repository.upload] make the upload in release work.

@lunny Yes, but I must add both [repository.upload] AND [attachment] the same ALLOWED_TYPES to make it work properly. Not just [repository.upload] OR [attachment]

Full config example (about upload):

[repository.upload]
ALLOWED_TYPES = application/zip|application/x-zip|application/x-zip-compressed|application/x-compress|application/x-compressed|multipart/x-zip

[attachment]
ENABLED       = true
PATH          = E:/my-work-spaces/Gitea/data/attachments
ALLOWED_TYPES = application/zip|application/x-zip|application/x-zip-compressed|application/x-compress|application/x-compressed|multipart/x-zip
MAX_SIZE      = 20
MAX_FILES     = 1

The configuration [repository.upload] is not in anywhere in the document currently.
( https://docs.gitea.io/en-us/config-cheat-sheet/ )

Problem seems to be resolved now.

However please consider my idea about file mime type verification only in one side (server side). To check mime type on client side (JS) can be a mess and duplicate task.

ALLOWED_TYPES = application/zip|application/x-zip|application/x-compressed-tar|application/x-compressed|application/x-gzip|application/x-compress|application/x-zip-compressed|multipart/x-zip

This is work for me. thanks.

I've followed the steps above (added to repository.upload & attachment) but am still unable to upload a .zip with the same error message.

So, I got the .zip to work, now I just need the .7z to work as well...

regarding 7z, adding application/x-7z-compressed did not work for me.
Above mime type is from mozilla.org - maybe it must be different?

Perheps a few usual file type should be in the default app.ini file!

Was this page helpful?
0 / 5 - 0 ratings