Export to GitHub

weed-fs - issue #28

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


Posted on Jul 11, 2013 by Grumpy Cat

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 Cat

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.

Comment #2

Posted on Jul 11, 2013 by Grumpy Cat

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.

Comment #3

Posted on Jul 12, 2013 by Massive Cat

Comment deleted

Comment #4

Posted on Jul 12, 2013 by Massive Cat

ok, this seams to work for me.

Attachments

Comment #5

Posted on Jul 12, 2013 by Grumpy Cat

Amazing! It worked well and I have checked it in to the HEAD!

Thanks Claudiu!

Comment #6

Posted on Jul 12, 2013 by Massive Cat

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 ?

Comment #7

Posted on Jul 12, 2013 by Grumpy Cat
  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.

Comment #8

Posted on Jul 12, 2013 by Quick Horse

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.

Comment #9

Posted on Jul 12, 2013 by Grumpy Cat

mime.TypeByExtension internally will also read the system mime settings.

Comment #10

Posted on Jul 12, 2013 by Grumpy Cat

Thomas, Thanks for the information. Very useful!

Status: Fixed

Labels:
Type-Defect Priority-Medium