Ruby on Rails Upload Without Database
uploader = CsvUploader . new
File . open ( file_path ) do |file |
something = uploader . store! ( file )
end
uploader . retrieve_from_store! ( self . file_name )
my_file = File . open ( './my_file.png' )
uploader = AvatarUploader . new
uploader . store! ( my_file ) # size: 1024x768
uploader . url # => '/url/to/my_file.png' # size: 800x600
uploader . thumb . url # => '/url/to/thumb_my_file.png' # size: 200x200
image = params [ :image ] . original_filename
path = File . join ( 'public' , 'images' , 'upload' , image )
File . open ( path , 'wb' ) { |f | f . write ( params [ :image ] . read ) }
file = params [ :image ]
file_name = file . original_filename
upload_file = file . tempfile
s3 = Aws ::S3 ::Resource . new ( region : ENV [ 'AWS_REGION' ] , access_key_id : ENV [ 'AWS_ACCESS_KEY' ] , secret_access_key : ENV [ 'AWS_SECRET_ACCESS_KEY' ] )
obj = s3 . bucket ( ENV [ 'AWS_BUCKET_NAME' ] ) . object ( file_name )
obj . upload_file ( upload_file , { acl : 'public-read' } )
render json : { data : obj . public_url } , status : 200