
weed-fs - issue #28
[HELP NEEDED] weed upload does not send correct mime type to weedfs
What steps will reproduce the problem? 1. weed update a_text_file.txt 2. when downloading, the mime type is not set 3.
What is the expected output? What do you see instead? It should send mime type information same as "curl -F".
Comment #1
Posted on Jul 11, 2013 by Massive CatYou can simply let users to specify a mime.types config file that maps mime to extension. Apache, nginx and the rest are doing similar thing.
weed volume -mime=/etc/mime.types ...
add mime according to mime.types file provided.
Use application/octet-stream for files without or unknown extension.
Comment #2
Posted on Jul 11, 2013 by Grumpy CatThat's one way to detect the mime type. But this current issue is that I am having trouble setting the mime type with Go's API. Need some coding help there.
Comment #3
Posted on Jul 12, 2013 by Massive CatComment deleted
Comment #4
Posted on Jul 12, 2013 by Massive Catok, this seams to work for me.
- weed.patch 474
Comment #5
Posted on Jul 12, 2013 by Grumpy CatAmazing! It worked well and I have checked it in to the HEAD!
Thanks Claudiu!
Comment #6
Posted on Jul 12, 2013 by Massive CatI'm glad!
However, there are few tweaks to add: 1. check if file name has an extension? If not, the file is text or binary? 2. some file names should be escaped (not sure how it is in Go) 3. mime.TypeByExtension is case insensitive? if not, string to lower? 4. file size > 0 ?
Comment #7
Posted on Jul 12, 2013 by Grumpy Cat- seems no extension still works? Default to binary? Need to investigate.
- Not sure to escape for what purpose.
- Done.
- 0 size file should be a valid file. I tested. It still works fine.
Comment #8
Posted on Jul 12, 2013 by Quick HorseExtension is a nice try, but for sure you should use some magic db like the unix "file" command. A pure go implementation is bitbucket.org/taruti/mimemagic - this would need the first 1024 bytes of the file data.
For the original question: use -v with curl to see what headers does it send; use --trace-ascii to let it save to a file to be able to investigate what to send.
Comment #9
Posted on Jul 12, 2013 by Grumpy Catmime.TypeByExtension internally will also read the system mime settings.
Comment #10
Posted on Jul 12, 2013 by Grumpy CatThomas, Thanks for the information. Very useful!
Status: Fixed
Labels:
Type-Defect
Priority-Medium