# Can page\_attachments store uploads in database?

**URL:** <https://www.ruby-forum.com/t/can-page-attachments-store-uploads-in-database/149815>\
**Category:** Radiant CMS\
**Created:** [September 30, 2008, 6:37am UTC](https://www.ruby-forum.com/t/can-page-attachments-store-uploads-in-database/149815 "2008-09-30T06:37:44Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![errolsiegel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/c77e96/32.png) [@errolsiegel](https://www.ruby-forum.com/u/errolsiegel)\
**Post date:** [September 30, 2008, 6:37am UTC](https://www.ruby-forum.com/t/can-page-attachments-store-uploads-in-database/149815/1 "2008-09-30T06:37:44Z")

</div>

I know attachment\_fu supports this, but I’m not sure if that means  
page\_attachments can work with it.

I wanted to see if anybody knows the answer to this before I spend the  
time on trial-and-error.

Thanks,  
Errol

---

<div class="post-metadata">

**Author:** ![errolsiegel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/c77e96/32.png) [@errolsiegel](https://www.ruby-forum.com/u/errolsiegel)\
**Post date:** [September 30, 2008, 6:40am UTC](https://www.ruby-forum.com/t/can-page-attachments-store-uploads-in-database/149815/2 "2008-09-30T06:40:42Z")

</div>

Please don’t do that. It does two things: It means that every file  
download has to hit your app server and it means that it has to pull  
it from the db which will be exceedingly slow. I don’t know if it’s  
possible with page\_attachments, but it should be avoided.

Nate

---

<div class="post-metadata">

**Author:** ![errolsiegel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/c77e96/32.png) [@errolsiegel](https://www.ruby-forum.com/u/errolsiegel)\
**Post date:** [September 30, 2008, 6:45am UTC](https://www.ruby-forum.com/t/can-page-attachments-store-uploads-in-database/149815/3 "2008-09-30T06:45:23Z")

</div>

In short, any backend that attachment\_fu supports works with  
page\_attachments. The amount of poking around in page\_attachments to  
get it working will vary.

---

<div class="post-metadata">

**Author:** ![errolsiegel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/c77e96/32.png) [@errolsiegel](https://www.ruby-forum.com/u/errolsiegel)\
**Post date:** [September 30, 2008, 6:53am UTC](https://www.ruby-forum.com/t/can-page-attachments-store-uploads-in-database/149815/4 "2008-09-30T06:53:04Z")

</div>

Nate: Thanks for the response. I agree that what you are saying is  
true. I am trying to balance performance against maintainability of the  
site. Perhaps you have a better suggestion for what I want to  
accomplish. I want to be able to run multiple version of the site (one  
for development and one for production). I understand that radiant has  
dev and prod ‘modes’ but this is not really quite what I want. For  
example I want to be able to edit a page (and its attachments) for  
somebody to review without modifying the existing production version of  
that page. I figured that if everything were stored in the database it  
would make things easier. I would just need to dump the dev database  
and import it into the prod database when I want to go live with  
changes. Thanks in advance for any suggesions you might have.

John: Thanks – perhaps I will try this if nobody has a better idea for  
managing content (based on what I wrote just above).

---

<div class="post-metadata">

**Author:** ![errolsiegel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/c77e96/32.png) [@errolsiegel](https://www.ruby-forum.com/u/errolsiegel)\
**Post date:** [September 30, 2008, 8:44am UTC](https://www.ruby-forum.com/t/can-page-attachments-store-uploads-in-database/149815/5 "2008-09-30T08:44:56Z")

</div>

Write a capistrano task to clone from staging to production. In the  
task clone both the database and static assets. It’s not much harder  
than cloning the db. Tar up the assets, copy them to the new  
location, then untar them. Remove old assets if necessary.

Nate

---

<div class="post-metadata">

**Author:** ![errolsiegel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/c77e96/32.png) [@errolsiegel](https://www.ruby-forum.com/u/errolsiegel)\
**Post date:** [September 30, 2008, 2:51pm UTC](https://www.ruby-forum.com/t/can-page-attachments-store-uploads-in-database/149815/6 "2008-09-30T14:51:45Z")

</div>

Errol,

If you add the appropriate database field(s) and tweak the model, you  
should get it to work. I have no idea how one would get the image data  
back out, however, since I’ve never done it.

Sean

---

<div class="post-metadata">

**Author:** ![errolsiegel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/c77e96/32.png) [@errolsiegel](https://www.ruby-forum.com/u/errolsiegel)\
**Post date:** [September 30, 2008, 5:57pm UTC](https://www.ruby-forum.com/t/can-page-attachments-store-uploads-in-database/149815/7 "2008-09-30T17:57:42Z")

</div>

There were dark times when we had like 200 000 images in the database,  
because the initial developers thought it’s the easiest way to control  
access to them for photo sharing and ordering website. So from that  
experience I can tell you that it would be slow as hell (it’s kind of  
obvious but still). For example Apache on my laptop can serve 1000+  
static files per second and only like 15-20 request/sec for php. My  
point is if you’re going to use this logic for production it will  
totally kill your performance.

If I were in your place I’d go with the capistrano task thing

Just my 2 cents

---

<div class="post-metadata">

**Author:** ![errolsiegel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/c77e96/32.png) [@errolsiegel](https://www.ruby-forum.com/u/errolsiegel)\
**Post date:** [October 3, 2008, 3:59pm UTC](https://www.ruby-forum.com/t/can-page-attachments-store-uploads-in-database/149815/8 "2008-10-03T15:59:16Z")

</div>

On Thu, Oct 2, 2008 at 6:59 PM, Errol S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Does anybody have any advice for how to go about this?
> 
> I’m pretty new to Capistrano. Is there a simple way to have Capistrano  
> tar up the files locally, upload them to the production server, then  
> replace the existing files with the uploaded files?
> 
> The last part seems easy enough – I get that I can use ‘run’ to run  
> commands on the remote server. I’m just not sure how to have it run  
> commands locally and upload files.

I too am curious about this. It would be great to have an entire copy of  
the  
production site on my laptop, but I have no idea which commands I would  
run  
to to make that happen. It was my impression, before looking into  
import\_export and super\_export, that those extensions did that kind of  
thing  
(with or without Capistrano). I was mistaken, but I am still curious how  
others are using those extensions on a daily basis to maintain some sort  
of  
parity between their dev and production sites.

~Nate

---

<div class="post-metadata">

**Author:** ![errolsiegel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/c77e96/32.png) [@errolsiegel](https://www.ruby-forum.com/u/errolsiegel)\
**Post date:** [October 3, 2008, 1:59am UTC](https://www.ruby-forum.com/t/can-page-attachments-store-uploads-in-database/149815/9 "2008-10-03T01:59:58Z")

</div>

I think I agree that having a task sync those files is going to be the  
best way to go.

Restricting access is not really an issue as (so far) I am just using  
page\_attachments for adding images to public pages.

Does anybody have any advice for how to go about this?

I’m pretty new to Capistrano. Is there a simple way to have Capistrano  
tar up the files locally, upload them to the production server, then  
replace the existing files with the uploaded files?

The last part seems easy enough – I get that I can use ‘run’ to run  
commands on the remote server. I’m just not sure how to have it run  
commands locally and upload files.

---

<div class="post-metadata">

**Author:** ![errolsiegel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/c77e96/32.png) [@errolsiegel](https://www.ruby-forum.com/u/errolsiegel)\
**Post date:** [October 3, 2008, 6:07pm UTC](https://www.ruby-forum.com/t/can-page-attachments-store-uploads-in-database/149815/10 "2008-10-03T18:07:43Z")

</div>

Nate:

Here is what I have picked up so far:

First, to answer one of my own questions, you can use ‘system’ in a  
capistrano task to run local commands (as opposed to using ‘run’ to run  
commands on remote servers).

Next, here are a couple of links to capistrano/rake tasks others have  
created to pull down databases and/or files from the production  
server(s) to the local dev machine:

[http://www.artima.com/forums/flat.jsp?forum=123&thread=185948](http://www.artima.com/forums/flat.jsp?forum=123&thread=185948)  
[http://nateclark.com/articles/tag/capistrano](http://nateclark.com/articles/tag/capistrano)

I suppose the benefit of using import\_export would be that in theory you  
could use it to move data between a mysql production database to an  
sqlite dev database (for example). The links above assume you are using  
the same type of database in both environments (perhaps a reasonable  
limitation for many people).
