Reputation: 576
UPDATE
I created a very simple app using paperclip having a Person model and avatar attachment. I then deployed it to a fresh new Dokku droplet and encountered the same issue as with my main App. I then read about ActiveStorage and thought maybe I'd see some success with that, so I converted the simple app to use ActiveStorage rather than Paperclip, but I still have the same issue on mobile uploads caught from the device camera.
This seems like an issue with Dokku from what I've seen (especially since the functionality works on Heroku), but I really don't know where to go from here. I don't have any special code for handling mobile uploads. I'm using simple_form for the form controls, and standard image_tag syntax for displaying. I'm also using Devise for user accounts (which I added to my simple app as well just to replicate). The thing is that my logs show nothing when I get the Dokku error message, it's like the request never makes it off of my phone.
Still looking for help on this, thanks!
I have an app that has paperclip uploads enabled for optional photos and PDFs attachments on my model. Everything works perfectly except in my production server when trying to attach files on Mobile (iOS).
I am using Dokku (via DigitalOcean) for Production, and Heroku for Test. I am using Amazon S3 for storage of file uploads.
Works:
Doesn't Work:
When I check the application logs from Dokku, I didn't see any errors. I enabled the live-mode logs (dokku logs application -t) to monitor while I tried an upload from mobile, and once I clicked the submit button, nothing was reported to the logs, it simply went to the error page on my device.
I am thinking it's an issue with my Dokku/deployment configuration, since it works fine in Heroku. I may be missing something on the Dokku side. I don't have HTTPS enabled on Heroku since I'm using the free tier, but I do have HTTPS enabled on Dokku via LetsEncrypt. I'm not sure if this could be the reason for the error or not.
Anyway, here is some relevant code from my app. Any ideas much appreciated!
Model.rb
has_attached_file :attachment,
styles: { large: ["1000x1000>", :png], medium: ["300x300>", :png], thumb: ["100x100>", :png] }
validates_attachment_content_type :attachment,
content_type: [
"image/jpg",
"image/jpeg",
"image/png",
"image/gif",
"application/pdf",
"file/txt",
"text/plain",
"application/doc",
"application/msword",
"application/vnd.ms-excel",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
],
message: "Sorry! We do not accept the attached file type"
model_controller.rb
def transaction_params
params.require(:transaction).permit(:trx_date, :description, :amount, :trx_type, :memo, :attachment, :attachment_file_name)
end
config/environments/production.rb
# Paperclip settings
config.paperclip_defaults = {
storage: :s3,
s3_credentials: {
bucket: ENV['S3_BUCKET_NAME'],
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
s3_region: ENV['S3_REGION'],
s3_host_name: ENV['S3_HOST_NAME']
}
}
Output of "dokku config myapp"
AWS_SECRET_ACCESS_KEY: **masked**
S3_BUCKET_NAME: mybucketname
DOKKU_APP_RESTORE: 1
DOKKU_NGINX_SSL_PORT: 443
S3_REGION: us-east-2
AWS_ACCESS_KEY_ID: **masked**
DOKKU_APP_TYPE: herokuish
DOKKU_NGINX_PORT: 80
DOKKU_PROXY_PORT_MAP: http:80:5000 https:443:5000
DATABASE_URL: **masked**
DOKKU_LETSENCRYPT_EMAIL: **masked**
S3_HOST_NAME: s3.us-east-2.amazonaws.com
Upvotes: 1
Views: 214
Reputation: 576
I determined the cause of the error by installing Postman and using the Proxy server to view more details about the client requests from my phone. I discovered the server was returning an error 413 Request Entity Too Large.
After some searching, I found that I needed to update my nginx configuration by adding the file in my app directory
/home/dokku/<myapp>/nginx.conf.d/upload.conf
In that file I inserted the line:
client_max_body_size 50M;
Afterwards I restarted my dokku container and everything works fine now :)
Thanks for the help all
Upvotes: 4