# Attempting to Insert File into DB But MYSQL "Goes away"

**URL:** <https://www.ruby-forum.com/t/attempting-to-insert-file-into-db-but-mysql-goes-away/138943>\
**Category:** Rails\
**Created:** [May 29, 2008, 7:58am UTC](https://www.ruby-forum.com/t/attempting-to-insert-file-into-db-but-mysql-goes-away/138943 "2008-05-29T07:58:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ror\_arch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ror\_arch](https://www.ruby-forum.com/u/ror_arch)\
**Post date:** [May 29, 2008, 7:58am UTC](https://www.ruby-forum.com/t/attempting-to-insert-file-into-db-but-mysql-goes-away/138943/1 "2008-05-29T07:58:14Z")

</div>

I am trying to upload a file to the DB but I am apparently unable to do  
so for the following reason :

ActiveRecord::StatementInvalid in StoragesController#create

Mysql::Error: MySQL server has gone away: INSERT INTO `storages`  
(`content_type`, `name`, `updated_at`, `created_at`, `data`)  
VALUES(‘application/pdf’, ‘Err’, ‘2008-05-29 01:39:35’, ‘2008-05-29  
01:39:35’, x’255044462d312e340a25c7ec8fa20a352030206f626a0a…

If I try to upload a file like a pdf or word or excel document it does  
not upload. I do get to upload small text files.

This is my view :

\<%= error\_messages\_for :storage %\>

\<%= form\_tag ({:action=\>‘create’}, :multipart=\>true) %\>

Name  
 \<%= text\_field 'storage' ,'name' %\>

 File  
 \<%= file\_field 'storage' ,'data' %\>

```
<%= submit_tag "Create" %>

```

 \<%= form\_tag %\>

This is my controller

def create  
@storage = Storage.new(params[:storage])

```
logger.debug(">>> storage #{@storage.name}")
    logger.debug(">>> storage #{@storage.data.content_type.chomp}")
@storage.content_type = @storage.data.content_type.chomp
@storage.data = @storage.data.read
respond_to do |format|
  if @storage.save
    flash[:notice] = 'Storage was successfully created.'
    format.html { redirect_to(@storage) }
    format.xml { render :xml => @storage, :status => :created,

```

:location =\> @storage }  
else  
format.html { render :action =\> “new” }  
format.xml { render :xml =\> @storage.errors, :status =\>  
:unprocessable\_entity }  
end  
end  
end

Do tell me if I am doing anything wrong please.
