# Message with multiple attachments

**URL:** <https://www.ruby-forum.com/t/message-with-multiple-attachments/70949>\
**Category:** Rails\
**Created:** [February 20, 2006, 6:42pm UTC](https://www.ruby-forum.com/t/message-with-multiple-attachments/70949 "2006-02-20T18:42:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![andremedeiros](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/90db22/32.png) [@andremedeiros](https://www.ruby-forum.com/u/andremedeiros)\
**Post date:** [February 20, 2006, 6:42pm UTC](https://www.ruby-forum.com/t/message-with-multiple-attachments/70949/1 "2006-02-20T18:42:02Z")

</div>

Hello.

I am implementing a system that allows you to add multiple attachments  
to a message. This raises a problem tho.

If I try to upload the attachments _BEFORE_ adding the message (thus  
creating an ID to relate the attachment to), I will need to find a way  
to store the attachments on a temporary way that will allow me to attach  
one another later. But, if the user closes the browser before inserting  
the message, I get temporary and unecessary files lying around. If I  
only allow one attachment at a time, this can also raise a few problems:

1. You add a 20mb attachment and then your form doesn’t validate, wich  
means you’ll have to upload again
2. You will have to edit that message to attach more files (wich, IMHO,  
doesn’t make much sense).

What would you do and how?

Thanks in advance,  
AndrÃ©

---

<div class="post-metadata">

**Author:** ![andremedeiros](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/90db22/32.png) [@andremedeiros](https://www.ruby-forum.com/u/andremedeiros)\
**Post date:** [February 20, 2006, 7:09pm UTC](https://www.ruby-forum.com/t/message-with-multiple-attachments/70949/2 "2006-02-20T19:09:56Z")

</div>

Hi AndrÃ©,

AndrÃ© Medeiros wrote:

> But, if the user closes the browser before inserting  
> the message, I get temporary and unecessary files lying around.

What makes you want to treat the files differently than any other  
session  
data? I’m new to this and about to jump off on my first ‘real’ project  
(i.e., will be deployed for use). Like yours, one piece of my app’s  
functionality is to allow the transfer of files to the user. I’d  
planned to  
treat the files more-or-less as ‘children’ that may need to be cleaned  
up  
just like all the other contents of any abandoned ‘cart.’ It sounds  
like  
maybe there’s something I need to be thinking about that I’m not. Any  
help  
will be much appreciated.

Thanks,  
Bill

---

<div class="post-metadata">

**Author:** ![andremedeiros](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/90db22/32.png) [@andremedeiros](https://www.ruby-forum.com/u/andremedeiros)\
**Post date:** [February 20, 2006, 7:23pm UTC](https://www.ruby-forum.com/t/message-with-multiple-attachments/70949/3 "2006-02-20T19:23:07Z")

</div>

Bill W. wrote:

> Hi AndrÃ©,
> 
> AndrÃ© Medeiros wrote:
> 
> > But, if the user closes the browser before inserting  
> > the message, I get temporary and unecessary files lying around.
> 
> What makes you want to treat the files differently than any other  
> session  
> data? I’m new to this and about to jump off on my first ‘real’ project  
> (i.e., will be deployed for use). Like yours, one piece of my app’s  
> functionality is to allow the transfer of files to the user. I’d  
> planned to  
> treat the files more-or-less as ‘children’ that may need to be cleaned  
> up  
> just like all the other contents of any abandoned ‘cart.’ It sounds  
> like  
> maybe there’s something I need to be thinking about that I’m not. Any  
> help  
> will be much appreciated.
> 
> Thanks,  
> Bill

I believe that files in this case cannot be treated as items that are  
added to a cart. That’s because adding an item to a cart takes only one  
click, 2secs waiting and maybe a 70kb download of new HTML. Uploading a  
file takes a little longer. That’s what worries me.

Any other suggestions?

Thanks in advance,  
AndrÃ©

---

<div class="post-metadata">

**Author:** ![andremedeiros](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/90db22/32.png) [@andremedeiros](https://www.ruby-forum.com/u/andremedeiros)\
**Post date:** [February 20, 2006, 8:27pm UTC](https://www.ruby-forum.com/t/message-with-multiple-attachments/70949/4 "2006-02-20T20:27:03Z")

</div>

Hi AndrÃ©,

I don’t think I’m grokking your app. If the file already exists in the  
file  
system, I’m not understanding why I wouldn’t just put the {path}file  
name to  
be transferred in the ‘cart.’ Why do I need to have the contents of the  
file in memory before the user commits to the transfer?

Users expect downloads to take time so my strategy is to do as little  
processing as possible in the pre-click state. The only thing the  
send\_file() method needs is the {path}filename. It even gives me the  
option  
to read the whole file into memory prior to transmit\_start or to stream  
it.  
Have you done a spike with send\_file() yet? What need(s) does it not  
satisfy?

I hope it’s clear that I’m really interested in your answer. Like I  
said, I  
share the need to transfer (a) file(s) to the user and I was under the  
impression from reading the send\_file() documentation that it was going  
to  
be pretty easy. If I’m wrong, it would be great to find out sooner  
rather  
than later 😉 Any info is greatly appreciated.

Best regards,  
Bill

----- Original Message -----  
From: “AndrÃ© Medeiros” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
To: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Sent: Monday, February 20, 2006 12:23 PM  
Subject: [Rails] Re: Message with multiple attachments
