Skip to content
This repository has been archived by the owner on May 9, 2019. It is now read-only.

Uploading Files

Florian Kasper edited this page Jul 19, 2014 · 1 revision

Uploading files to your Git repository

Since version 1.5.13 GollumRails has the ability to upload files directly into your GIT repository.

Configuration

Model (not necessarily needed)

You can define a model, where you can customize your uploads further:

app/models/upload.rb

class Upload < GollumRails::Upload
end

Uploading files

# Signature: #initialize(file:SomeSortOfRackFileupload , destination:String)
# File is a Rack file upload:
# <input type="file" name="file" />
upload = Upload.new(file: params[:file], destination: 'uploads')
upload.save #or save! if you want exceptions to be thrown instead of returning false

OR:

upload = Upload.create(file: params[:file], destination: 'uploads')

Customizing

Blacklisting filetypes

You can easily blacklist Files by extension name. e.g. file.tar.gz has the extension .gz.

class Upload < GollumRails::Upload
  blacklist_format :gz, :png
end

Whitelisting filetypes

class Upload < GollumRails::Upload
  whitelist_format :tar, :bz2
end

Specify a maximum file size

class Upload < GollumRails::Upload
  max_filesize 2.megabytes
end

Specify a default upload directory

class Upload < GollumRails::Upload
  upload_directory 'uploads'
end

now you don't need to append your destination to your instance call anymore:

upload = Upload.create(file: params[:file])