shrine: Upload endpoint not working

I’m trying to integrate this gem with fineuploader fron-end library to enhance the user experience (http://fineuploader.com/). The fineupload plugin require us to specify the URL where it should send uploads and server requests to. This endpoint can be an absolute path or a relative path. More information could be found here: http://docs.fineuploader.com/quickstart/02-setting_options.html

I’ve read shrine gem docs section: https://github.com/janko-m/shrine#direct-uploads and I’ve setup my endpoint in routes.rb as mount ImageUploader::UploadEndpoint, at: "/attachments/images" and I’m setting my endpoint in fineupload initializing function as:

    $("#fine-uploader-gallery").fineUploader({
        request: {
            endpoint: '/attachments/images/cache/upload'
        },
    });

But on network tab of chrome inspector, I can see that post request to this URL cause a status of 404. What could be the issue? Do I need to pass some parameters along with this endpoint? if so how to receive those parameters in my fineuploader function?

PS: I’m using this repository as base: https://github.com/erikdahlstrand/shrine-rails-example and I want to use fineuploader instead of jQuery file upload library.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 16 (6 by maintainers)

Most upvoted comments

I assume you meant this app: https://github.com/erikdahlstrand/shrine-rails-example 😉

Is the puts statement visible in the logs when you curl the endpoint now? I see that curl returned application/json Content-Type, so it seems that it is indeed hitting it.

Ok, I think I know now. If you load the direct_upload plugin with presign: true, it’s going to include the only the presign route (/:storage/presign). I originally disabled the /:storage/upload route in that case for security reasons, but then I realized there are no security issues and it adds confusion, so I changed it in the latest version to always return both routes. Sorry for the confusion 😅

So you just need to update to 2.2.0, and it should work.

Well, for anybody who will be following this topic. The fineuploader library sends some parameters (to shrine upload endpoint) when some file is uploaded. These params names are qquuid, qqfilename, qqtotalfilesize, qqfile.

Now, since shrine gem is expecting the uploaded file in a param named file the request was responding with a 400 status before. So, we’ve to change the sent params name for qqfile parameter. For this the fineuploader provide some options, for detail: http://docs.fineuploader.com/api/options.html#request

So, after setting my fineuploader initializing code like following, now the request to upload endpoint is responding with a 200 status code and I can see the file uploaded in my aws S3 bucket in cache folder.

    $("#fine-uploader-gallery").fineUploader({
        request: {
            endpoint: '/attachments/images/cache/upload',
            inputName: "file",
        },
    });

However, fineuploader requires a specific kind of JSON response. Well, it’s another issue, see: http://docs.fineuploader.com/endpoint_handlers/traditional.html#response

Maybe FineUploader isn’t passing the file via file parameter (multipart upload), you can try to look into FineUploader docs. You can inspect what params are sent by putting binding.pry in the before filter, and inspecting request.params:

require "pry"
ImageUploader::UploadEndpoint.before { binding.pry }
pry >> request.params

This curl output is expected, because you have to pass the actual file.