{"action":"created","issue":{"url":"https://api.github.com/repos/janko-m/shrine/issues/101","repository_url":"https://api.github.com/repos/janko-m/shrine","labels_url":"https://api.github.com/repos/janko-m/shrine/issues/101/labels{/name}","comments_url":"https://api.github.com/repos/janko-m/shrine/issues/101/comments","events_url":"https://api.github.com/repos/janko-m/shrine/issues/101/events","html_url":"https://github.com/janko-m/shrine/issues/101","id":186968237,"number":101,"title":"Heroku Internal Server Error","user":{"login":"jakehockey10","id":1821383,"avatar_url":"https://avatars.githubusercontent.com/u/1821383?v=3","gravatar_id":"","url":"https://api.github.com/users/jakehockey10","html_url":"https://github.com/jakehockey10","followers_url":"https://api.github.com/users/jakehockey10/followers","following_url":"https://api.github.com/users/jakehockey10/following{/other_user}","gists_url":"https://api.github.com/users/jakehockey10/gists{/gist_id}","starred_url":"https://api.github.com/users/jakehockey10/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jakehockey10/subscriptions","organizations_url":"https://api.github.com/users/jakehockey10/orgs","repos_url":"https://api.github.com/users/jakehockey10/repos","events_url":"https://api.github.com/users/jakehockey10/events{/privacy}","received_events_url":"https://api.github.com/users/jakehockey10/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-11-03T02:44:28Z","updated_at":"2016-11-03T04:23:19Z","closed_at":"2016-11-03T04:23:19Z","body":"Hello,\r\n\r\nI was wondering if I could get some help getting pointed in the right direction.  I am successfully using shrine to upload photos when running my server locally.  Unfortunately, pushing things up to Heroku for some staging testing has shown different behavior.  When I attempt to upload a file, I receive this error when I check my production logs:\r\n\r\n```\r\nStarted GET \"/images/upload/cache/presign?extension=.jpg&_=<numbers>\r\nNoMethodError (undefined method `object' for nil:NilClass \r\nDid you mean?  object_id): \r\nvendor/bundle/ruby/2.3.0/gems/shrine-2.4.0/lib/shrine/storage/s3.rb:293:in `object'\r\n```\r\n\r\nI have a file in my asset pipeline named `uploads.js.erb`:\r\n\r\n```javascript\r\n$(document).on('turbolinks:load', function () {\r\n  $(document).on('new-file-input', function () {\r\n    $('input[type=file]').fileupload({\r\n      add: add,\r\n      progress: progress,\r\n      done: done\r\n    });\r\n\r\n    function add (e, data) {\r\n      console.log('add', data);\r\n\r\n      data.progressBar = $('<div class=\"progress\" style=\"width: 300px\"><div class=\"progress-bar\"></div></div>').insertAfter('input[type=\"file\"]');\r\n\r\n      var options = {\r\n        extension: data.files[0].name.match(/(\\.\\w+)?$/)[0], // set the file extension\r\n        _: Date.now() // prevent caching\r\n      };\r\n\r\n      $.getJSON('/images/upload/cache/presign', options, function (result) {\r\n        console.log('presign', result);\r\n        data.formData = result['fields'];\r\n        data.url = result['url'];\r\n        data.paramName = 'file'; // Amazon S3 requires this to be 'file'\r\n        data.submit();\r\n      });\r\n    }\r\n\r\n    function progress (e, data) {\r\n      console.log('progress', data);\r\n\r\n      var progress = parseInt(data.loaded / data.total * 100, 10);\r\n      var percentage = progress.toString() + '%';\r\n\r\n      data.progressBar.find('.progress-bar').css('width', percentage).html(percentage);\r\n    }\r\n\r\n    function done (e, data) {\r\n      console.log('done', data);\r\n\r\n      data.progressBar.remove();\r\n\r\n      $('<i class=\"fa fa-spinner fa-pulse fa-5x\"></i><p>Finished uploading to S3...now processing and saving to Rails...</p>').insertAfter('input[type=\"file\"]');\r\n\r\n      var image = {\r\n        id: data.formData.key.match(/cache\\/(.+)/)[1], // we have to remove the prefix\r\n        storage: 'cache',\r\n        metadata: {\r\n          size: data.files[0].size,\r\n          filename: data.files[0].name.match(/[^\\/\\\\]+$/)[0], // IE return full path\r\n          mime_type: data.files[0].type\r\n        }\r\n      };\r\n\r\n      var form = $(this).closest('form');\r\n      var form_data = new FormData(form[0]);\r\n      form_data.append($(this).attr('name'), JSON.stringify(image));\r\n\r\n      $.ajax(form.attr('action'), {\r\n        contentType: false,\r\n        processData: false,\r\n        data: form_data,\r\n        method: form.attr('method'),\r\n        dataType: 'script'\r\n      }).done(function (data) {\r\n        console.log('done from rails', data);\r\n      });\r\n    }\r\n  });\r\n});\r\n```\r\n\r\nand the `new-file-input` is triggered when the server responds with a `js` response in the form of `new.js.erb`:\r\n\r\n```javascript\r\n$('.more-photos-separator').after('<%= j render 'photos/form' %>');\r\n$(document).trigger('new-file-input');\r\n```\r\n\r\nThe add function is being called when the image is chosen in the file field, but I seemingly immediately get the mentioned error serverside.\r\n\r\nI followed the tutorial found at gorails.com, and everything works just about how I want it to locally, so I pushed to my staging app in Heroku and I don't know how to diagnose the problem.\r\n\r\nThank you!"},"comment":{"url":"https://api.github.com/repos/janko-m/shrine/issues/comments/258062054","html_url":"https://github.com/janko-m/shrine/issues/101#issuecomment-258062054","issue_url":"https://api.github.com/repos/janko-m/shrine/issues/101","id":258062054,"user":{"login":"janko-m","id":795488,"avatar_url":"https://avatars.githubusercontent.com/u/795488?v=3","gravatar_id":"","url":"https://api.github.com/users/janko-m","html_url":"https://github.com/janko-m","followers_url":"https://api.github.com/users/janko-m/followers","following_url":"https://api.github.com/users/janko-m/following{/other_user}","gists_url":"https://api.github.com/users/janko-m/gists{/gist_id}","starred_url":"https://api.github.com/users/janko-m/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/janko-m/subscriptions","organizations_url":"https://api.github.com/users/janko-m/orgs","repos_url":"https://api.github.com/users/janko-m/repos","events_url":"https://api.github.com/users/janko-m/events{/privacy}","received_events_url":"https://api.github.com/users/janko-m/received_events","type":"User","site_admin":false},"created_at":"2016-11-03T04:23:18Z","updated_at":"2016-11-03T04:23:18Z","body":"This error is because your S3 credentials are not properly set on Heroku, at least the bucket name, because it is being sent as `nil` to the S3 storage.\r\n\r\nIf you're fetching your S3 credentials from environment variables, I recommend to always use `ENV.fetch`, so that it loudly fails if an ENV variable is missing.\r\n\r\n```rb\r\n# silently returns nil if variable is missing\r\nENV[\"S3_BUCKET\"]\r\n\r\n# loudly fails with a KeyError if variable is missing\r\nENV.fetch(\"S3_BUCKET\")\r\n```"}}
{"actor":{"display_login":"janko-m"}}