using attachments to store images

198 views
Skip to first unread message

Sylvain Reverdy

unread,
Mar 9, 2012, 3:43:15 AM3/9/12
to rav...@googlegroups.com
Hi,
 
I'm storing images as attachment using the session.Advanced.DatabaseCommands.PutAttachment command.
It works, but if I try to get directly the image from the browser (http://localhost/raven/static/images/image.jpg), it returns the data with the content-type "text/html" instead of "image/jpeg".
So, in Google Chrome, it does not render the image, it shows binary data...

I don't understand how to pass the content type using the PutAttachment method.
I suppose it is possible because the website Ravendb.net uses it... (http://ravendb.net/static/images/bg-main-t.jpg)

Should I set something on the RavenJObject ?
 
Thx,
Sylvain

Oren Eini (Ayende Rahien)

unread,
Mar 9, 2012, 4:10:23 AM3/9/12
to rav...@googlegroups.com
Sylvain,
Yes, the PutAttachment accepts a metadata object, and you can put the Content-Type there that will be returned.

Sylvain Reverdy

unread,
Mar 9, 2012, 1:34:27 PM3/9/12
to rav...@googlegroups.com
Thx for the answer.
 
It's not working on my computer :
 
Here's my code :
 
using (Stream s = File.OpenRead(@"D:image.jpg"))
{
    session.Advanced.DatabaseCommands.PutAttachment("images/image.jpg", null, s,
          new RavenJObject { { "Content-Type", "image/jpeg" } });
    session.SaveChanges();
}
 
I host RavenDB on IIS 7.5...
 
Here is the response data (using Fiddler)

HTTP/1.1 200 OK
Cache-Control: private
Content-Type: text/html
ETag: 00000000-0000-0d00-0000-000000000002
Server: Microsoft-IIS/7.5
Raven-Server-Build: 700
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Fri, 09 Mar 2012 18:30:48 GMT
Content-Length: 70130

Oren Eini (Ayende Rahien)

unread,
Mar 11, 2012, 8:07:54 AM3/11/12
to rav...@googlegroups.com
You are correct, fixed in the next build 

Sylvain Reverdy

unread,
Mar 12, 2012, 1:54:29 PM3/12/12
to rav...@googlegroups.com
Ok, thx for this information.

2012/3/11 Oren Eini (Ayende Rahien) <aye...@ayende.com>

Sylvain Reverdy

unread,
Apr 9, 2012, 4:47:17 AM4/9/12
to rav...@googlegroups.com
I tried with the last stable build (888), and now the server is giving me a content-type "application/json; charset=utf-8" instead of "image/jpeg" :

 HTTP/1.1 200 OK
Cache-Control: private
Content-Type: application/json; charset=utf-8
ETag: 00000000-0000-3800-0000-000000000005
Server: Microsoft-IIS/7.5
Raven-Server-Build: 888
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Mon, 09 Apr 2012 08:42:18 GMT
Content-Length: 70130

 I used the same code to put the attachment

using (Stream s = File.OpenRead(@"D:\image.jpg"))
{
session.Advanced.DatabaseCommands.PutAttachment("images/image.jpg", null, s,
new RavenJObject { { "Content-Type", "image/jpeg" } });
session.SaveChanges();
}
 
Am I missing something, or is the bug still there ?
 
2012/3/12 Sylvain Reverdy <sylvain...@gmail.com>

Itamar Syn-Hershko

unread,
Apr 10, 2012, 8:29:26 PM4/10/12
to rav...@googlegroups.com
We have a passing test for this:

Raven.Tests.MailingList.AttachmentContentType

Can you see why your code fails?

Also, you don't need to call session.SaveChanges() after calls to DatabaseCommands (which you can access directly from the document store object)

Sylvain Reverdy

unread,
Apr 10, 2012, 9:35:10 PM4/10/12
to rav...@googlegroups.com
Thx your answer
My Bad.
I updated the server, but forgot to update the client.
Now it is working :)


 
2012/4/10 Itamar Syn-Hershko <ita...@hibernatingrhinos.com>
361.gif
Reply all
Reply to author
Forward
0 new messages