Http server and images

589 views
Skip to first unread message

elliot

unread,
Mar 12, 2013, 12:11:24 PM3/12/13
to ve...@googlegroups.com
 Is there any in-built method for serving image files over http(s), rather than doing something like this:

request.response.putHeader("content-type", "image/*");
String fileName = "myfile.jpg";
File file = new File(fileName);
byte[] fileContent = Files.readAllBytes(file.toPath());
request.response.writeBuffer(new Buffer().appendBytes(fileContent));
request.response.end();


Elliot


Christian Essl

unread,
Mar 12, 2013, 1:15:04 PM3/12/13
to ve...@googlegroups.com
request.response.sendFile(fileName);

Tim Fox

unread,
Mar 12, 2013, 1:46:38 PM3/12/13
to ve...@googlegroups.com
On 12/03/13 17:15, Christian Essl wrote:
request.response.sendFile(fileName);


Actually - it should set content-type automatically for most common types :)



On Tuesday, March 12, 2013 5:11:24 PM UTC+1, elliot wrote:
 Is there any in-built method for serving image files over http(s), rather than doing something like this:

request.response.putHeader("content-type", "image/*");
String fileName = "myfile.jpg";
File file = new File(fileName);
byte[] fileContent = Files.readAllBytes(file.toPath());
request.response.writeBuffer(new Buffer().appendBytes(fileContent));
request.response.end();


Elliot


--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Christian Essl

unread,
Mar 12, 2013, 2:15:30 PM3/12/13
to ve...@googlegroups.com


On Tuesday, March 12, 2013 6:46:38 PM UTC+1, Tim Fox wrote:
On 12/03/13 17:15, Christian Essl wrote:
request.response.sendFile(fileName);


Actually - it should set content-type automatically for most common types :)

Nice  

elliot

unread,
Mar 12, 2013, 6:56:02 PM3/12/13
to ve...@googlegroups.com
Hmm...

Serving images with the sendFile method seems to hang & timeout, producing a browser 404.  I have no issue with text/html however.  Thought it may be an odd permission issue on the folder but they are all open and the path looks fine so I am a little confused.

The mime type detection is nice - is the type determined by extension, magic headers or other?

Elliot

elliot

unread,
Mar 12, 2013, 7:21:27 PM3/12/13
to ve...@googlegroups.com
Actually this looks like Windows B.S. so forget I typed anything......except the question on the mime types :)

Tim Fox

unread,
Mar 12, 2013, 7:24:06 PM3/12/13
to ve...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages