Skip to content

Commit

Permalink
Missing gem for base64 uploaded file, update the swagger file wrong C…
Browse files Browse the repository at this point in the history
…Ontent-Type
  • Loading branch information
brunto committed Dec 1, 2017
1 parent 044dd26 commit 1b5d256
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 53 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ gem 'rails', '~> 5.0.6'
gem 'puma', '~> 3.0'
gem 'pg'
gem 'carrierwave', '~> 1.0'
gem 'carrierwave-base64', '~> 2.6.1'
gem 'figaro'


Expand Down
6 changes: 5 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ GEM
activemodel (>= 4.0.0)
activesupport (>= 4.0.0)
mime-types (>= 1.16)
carrierwave-base64 (2.6.1)
carrierwave (>= 0.8.0)
mime-types (~> 3.0)
case_transform (0.2)
activesupport
concurrent-ruby (1.0.5)
Expand Down Expand Up @@ -142,6 +145,7 @@ DEPENDENCIES
active_model_serializers (~> 0.10.0)
byebug
carrierwave (~> 1.0)
carrierwave-base64 (~> 2.6.1)
factory_girl_rails (~> 4.0)
figaro
listen (~> 3.0.5)
Expand All @@ -154,4 +158,4 @@ DEPENDENCIES
tzinfo-data

BUNDLED WITH
1.14.6
1.16.0
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ Then, in the PIA application use this URL to activate the server mode. Fill the

![PIA Settings](public/pia-settings.png)

Run the application in production mode
--------------------------------------

1. Fill the `production` section in the `database.yml`file.
2. Create the database: `RAILS_ENV=production bin/rake db:create`
3. Create the tables: `RAILS_ENV=production bin/rake db:migrate`
4. Precompile the assets: `RAILS_ENV=production rake assets:precompile`
5. Run the server: `RAILS_ENV=production bin/rails s`

Run the test
------------

Expand Down
9 changes: 8 additions & 1 deletion app/controllers/attachments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ def show_signed
# POST /attachments
def create
@attachment = Attachment.new(attachment_params)
@attachment.filename = params[:attachment][:name]
file = params[:attachment][:file]
mime_type = params[:attachment][:mime_type]
file = file.gsub('data:application/octet-stream;base64', "data:#{mime_type};base64")
@attachment.attached_file = file

if @attachment.save
render json: @attachment, status: :created
Expand Down Expand Up @@ -52,6 +57,8 @@ def set_attachment

# Only allow a trusted parameter "white list" through.
def attachment_params
params.fetch(:attachment, {}).permit(:attached_file, :pia_signed).merge(params.permit(:pia_id))
params.fetch(:attachment, {})
.permit(:pia_signed)
.merge(params.permit(:pia_id))
end
end
4 changes: 3 additions & 1 deletion app/models/attachment.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class Attachment < ApplicationRecord
mount_uploader :attached_file, FileUploader
mount_base64_uploader :attached_file, FileUploader, file_name: -> (a) { a.filename }
belongs_to :pia, inverse_of: :attachments

attr_accessor :filename
end
49 changes: 0 additions & 49 deletions app/uploaders/file_uploader_uploader.rb

This file was deleted.

2 changes: 1 addition & 1 deletion swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ basePath: /
schemes:
- https
consumes:
- application/json
- multipart/form-data
produces:
- application/json
paths:
Expand Down

0 comments on commit 1b5d256

Please sign in to comment.