Hi CJ,
the ruby code from the web page below
class DataFile < ActiveRecord::Base
def self.save(data, name, directory)
# create the file path
path = File.join(directory, name)
# write the file
File.open(path,‘wb’) do |file|
file.puts data.read
end
end
end
class UploadController < ApplicationController
def index
# capture incoming file params from flash
data = params[:Filedata]
name = params[:Filename]
# the directory in which to save the file
directory = ‘public/uploads’
# save the file
@data_file = DataFile.save(data, name, directory)
# there’s no view so render nothing
render :nothing => true
end
end
is already in web2py. So if you just have to do something like
db.define_table('DataFile',SQLField('Filename'),SQLField('Filedata','upload'))
def index(): return SQLFORM(db.DataFile).accepts(request.vars,formname=None)
you get exactly the same functionality as the above ruby code + definition of the table + built-in security (the ruby code above is very insecure)!
Massimo