varun2784 / weed-fs

Automatically exported from code.google.com/p/weed-fs
0 stars 0 forks source link

[HELP NEEDED] weed upload does not send correct mime type to weedfs #28

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
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".

Original issue reported on code.google.com by chris...@gmail.com on 11 Jul 2013 at 7:00

GoogleCodeExporter commented 8 years ago
You 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.

Original comment by claudiu....@gmail.com on 11 Jul 2013 at 9:42

GoogleCodeExporter commented 8 years ago
That'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.

Original comment by chris...@gmail.com on 11 Jul 2013 at 9:55

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
ok, this seams to work for me.

Original comment by claudiu....@gmail.com on 12 Jul 2013 at 1:47

Attachments:

GoogleCodeExporter commented 8 years ago
Amazing! It worked well and I have checked it in to the HEAD!

Thanks Claudiu!

Original comment by chris...@gmail.com on 12 Jul 2013 at 2:16

GoogleCodeExporter commented 8 years ago
I'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 ?

Original comment by claudiu....@gmail.com on 12 Jul 2013 at 3:07

GoogleCodeExporter commented 8 years ago
1. seems no extension still works? Default to binary? Need to investigate.
2. Not sure to escape for what purpose.
3. Done.
4. 0 size file should be a valid file. I tested. It still works fine.

Original comment by chris...@gmail.com on 12 Jul 2013 at 4:31

GoogleCodeExporter commented 8 years ago
Extension 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.

Original comment by tgulacs...@gmail.com on 12 Jul 2013 at 5:09

GoogleCodeExporter commented 8 years ago
mime.TypeByExtension internally will also read the system mime settings.

Original comment by chris...@gmail.com on 12 Jul 2013 at 5:59

GoogleCodeExporter commented 8 years ago
Thomas, Thanks for the information. Very useful!

Original comment by chris...@gmail.com on 12 Jul 2013 at 6:01