# Create FileColumn Image without a From

**URL:** <https://www.ruby-forum.com/t/create-filecolumn-image-without-a-from/135163>\
**Category:** Rails\
**Created:** [April 18, 2008, 5:07pm UTC](https://www.ruby-forum.com/t/create-filecolumn-image-without-a-from/135163 "2008-04-18T17:07:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![phil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e95f7d/32.png) [@phil](https://www.ruby-forum.com/u/phil)\
**Post date:** [April 18, 2008, 5:07pm UTC](https://www.ruby-forum.com/t/create-filecolumn-image-without-a-from/135163/1 "2008-04-18T17:07:47Z")

</div>

Hey,

im creating a new bookmark with a form and i’m uploading an image with  
File Column. This works well!

But another function is to copy this bookmark. That means it will be  
created a new Object, with an new Id. All the other attributes should  
be copied from the original. That works, but not with the “image”  
attribute. Thats where the fileColumn Image is placed. Im getting the  
error:

'Do not know how to handle a string with value ‘/path/Bild\_4.jpg’

I think fileColumn expects an File, and not an string url. But i don’t  
know to solve this Problem ☹

Here is my Code:

@bookmark = Bookmark.new(:title =\> oldBookmark.title,  
:url =\> oldBookmark.url,  
:description =\> oldBookmark.description,  
:confirmed =\> 0,  
:user =\>User.find(session[:user]),  
:image =\> oldBookmark.image )

@bookmark.save

Maybe someone has an idea? Thanks a lot!

---

<div class="post-metadata">

**Author:** ![phil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e95f7d/32.png) [@phil](https://www.ruby-forum.com/u/phil)\
**Post date:** [April 18, 2008, 5:32pm UTC](https://www.ruby-forum.com/t/create-filecolumn-image-without-a-from/135163/2 "2008-04-18T17:32:33Z")

</div>

I’m not sure what you mean fully, but I think you mean save an item from  
the  
FS or URL…not uploaded via a form

here is an example from when I used a FileColumn to upload an image to  
my  
database using a URL (it is 2 years old and very ugly code)

essentially in your case just treat your string as I do the URL

_in environment.rb have:_  
require ‘ftools’  
require ‘fileutils’

_and in your controller something like_

raise if not orig =~  
/^(http|https)://[a-z0-9]+([-.]{1}[a-z0-9]+)_.[a-z]{2,5}(([0-9]{1,5})?/._)?$/ix

```
   logger.error "???????????? VALUE >> #{orig}"
   response = false
      #if good url format, get the file
      tn = open(orig)
      filename = orig.split("/")

      tp = tn.path
      nf = File.new(tp)
      nf_path = File.split(nf.path)

      f = "#{nf_path[0]}" << "/" << "#{filename.last}"

      #dreamhost is case sensitive, this is for URL's only
      f = f.downcase
      logger.error "FFFFFFFFFFF #{f}"

      FileUtils.touch f

      #sleep 2
      ff = File.new("#{f}")
      FileUtils.copy nf.path, ff.path

      @tile.img_name = File.new(ff.path) #gold

   rescue
      if response == false
        logger.error "???????????? BAD URL >> #{orig}"
      end
   end
 else
  #if orig is empty
  logger.error "ZZZZZZZZZZZZZZZZZZZ NO URL >> #{orig}"
 end

#if both img fields are empty: upload a default img (for now)
if @tile.img_name.nil?
  #@tile.img_name = File.new(RAILS_ROOT + 

```

“/public/images/rails.png”)  
#gold default if they do not upload a file  
logger.error “??? no FILE”  
if @tile.img\_path.empty? or response == false  
@tile.img\_name = File.new(RAILS\_ROOT +  
“/public/images/default.jpg”)  
#gold default if they do not upload a file  
logger.error “??? no URL”  
end  
else  
#params[:tile][:img\_name].path.downcase  
end

if @tile.save  
#email admin about new tile  
MailMe::deliver\_new\_tile(@session[:user], @tile.id);

```
    @ts_e.save
    if session[:user].login == "anonymous"
      redirect_to :controller => '/user/logout'
    else
      redirect_to :controller => '/user/account/'
    end
  else
    render :action => 'index' #should go back to upload_tile
  end

```

checkout working example at [www.blogsaic.com/tile](http://www.blogsaic.com/tile)

no login required
