-1

I am converting MS Word documents to HTML, which I am then going to display in an I-frame in an HTML5 canvas, along with other interactive elements.

Of course the converted document will be a web page with html, css, image, etc files all contributing to the final display.

I am storing all of my multi-media in this application in GridFS in Mongodb. It is being served up by a servlet.

Is there a good strategy or implementation I can use to store in mongodb, all of the files that go into making up the web page? I thought about saving the directory in a zip file in GridFS, but I don't want to unzip in order to serve up the content.

4

1 回答 1

2

I see that solution for this problem is pretty simple:

  1. You need to make sure that all links in html/css/js are relative (you can convert them from absolute to relative when you save them in mongodb).

  2. Your servlet should handle properly all requests, parse the request path, read requested resource and return it as a result.

For example. Let's assume that you have page testA.html, testB.html, script.js and style.css. You store all of them in MongoDB, so you should know the name of file and it's content. Let's take a look what you will need to handle:

  1. user requests page http://yourmongodb/testA.html - your servlet parses this url, finds that it expects document testA.html, so you need to find this document in mongodb and return it's content.
  2. Browser parses content of testA.html and finds script.js and style.css. If you keep everything as relative addresses, so browser will do two additional requests: http://yourmongodb/script.js and http://yourmongodb/style.css, which again tells you what you need to find in mongodb and what you need to return.
  3. If testA.html has link to testB.html (and link is relative) - when user will click on link - browser will request http://yourmongodb/testB.html.

If you also want to support directories you can keep this information as a additional peace in files collection.

于 2013-07-29T23:01:49.320 回答