I am using http://img.tweetimag.es/ to pull twitter avatars.
EX:
http://img.tweetimag.es/i/joestump_o
How do I know the correct mime type (jpg, png, gif, etc.) to save locally?
Any help would be great, thanks.
JP
Look at the content type of the HTTP GET request. For your example:
Content-Type: image/png
Here are some values you can retrieve, as mentioned in #kgiannakakis answer, take a look at Content-Type:
http://img694.imageshack.us/img694/2144/unledofv.png
Related
Use case:
Let's say we have www.example.org/statistics/ - with text/json it responses with JSON representation of raw data, with text/html it gives representation for human beings, with beauty, graphs, interactivity etc.
Is this good practice?
Yes, it's called Content Negotiation and it's great way to keep your URLs nice and tidy.
I need to know setting the content-type for an S3 object while uploading is important or it will take the default content-type automatically? Also, which is the good practice?
Also, I want to know if I set the content-type to some thing else
(for ex: application/vnd.openxmlformats-officedocument.wordprocessingml.document) when uploading and specify the content-type as "application/octet-stream" when downloading, will it work?
Thanks in advance.
It depends on how you are going to use content-type.
As far as S3 is concerned, it doesn't matter.
But if you intend to transmit this file to a user via browser then it is good to have right content-type so that browser can identify file type and act accordingly instead of simply showing a "download file" dialog.
Right content type can help a browser to open the file with proper application either integrated with browser(like pdf reader) or stand alone application (like MS Word)
I am studying a book here and there is a exercise that needs 2 HTML files and I want to know if its possible to have to HTML files in my JsFidle
I do not believe it is possible. However, You could use Plunker. It's pretty similar, but allows you to create multiple files with your name extension. Was using it the other week to have a CSV as a data source.
Plunker Site here
This should help.
http://doc.jsfiddle.net/use/gist_response.html
Content of the http://gist.github.com/raw/606699/fiddle.response.html will be returned with text/html MIME type if this url will be loaded http://jsfiddle.net/gh/gist/response.html/606699/ using Ajax request.
.
is it necessary to mention content-type in http header while uploading the file. i tried using c#. i had set it "image/png" while uploading a pdf file and when i downloaded the uploaded file, the pdf file was perfect. it didn't get corrupted.
so what is the role of specifying content-type in http header.
can it be null or any other wrong value.
because the application that i am making, user will just give the file and and i just need to upload it.
any help highly appreciated. thanks in advance.
Weird that nobody answered this question.
You should always set the content-type, some software (servers) may break when it's omitted.
You could give it any value that the target system can handle.
Since you can easily fake http request, you can also fake the headers.
So your target system (in this case an upload processor) should only accept content-type
values it's able to handle and you MUST validate if the given content-type actually matches the data that is send in the body (the uploaded file itself).
You can never trust the content-type value, until you validate it somehow.
As a PHP developer I always check any file upload against a mime-type validator to be sure I got what I expected. For example I use getimagesize() to detect whether it's an image or not and if it is to get it's file format type (PNG).
Since both PNG and PDF files are binary file formats your upload succeeded.
This is because you coded it that way or the target system falls back on default settings or does some checking for itself.
i'm using Moscow ML combined with CGI. I have a site that calculates simple arithmetics. When the submit button i pushed, the site is redirected to the actual CGI file that outputs the result of the calculation. Although in my case, it outputs the html code in raw form rather then actually outputting the result in html. Anybody that knows a solution to this problem ? // thx beforehand
It sounds like you are missing a content-type http header such as:
Content-type: text/html; charset=utf-8