Git Product home page Git Product logo

Comments (16)

janko avatar janko commented on May 21, 2024 2

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.

from shrine.

janko avatar janko commented on May 21, 2024 1

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.

from shrine.

imfaisalkh avatar imfaisalkh commented on May 21, 2024 1

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

from shrine.

janko avatar janko commented on May 21, 2024

Hmm, that's strange. The upload endpoint needs to receive a file parameter, but I'm sure that FineUploader sends it by default, because it's a convention. And if it doesn't, the response status wouldn't be "404 Not Found", but "400 Bad Request".

What happens if you try to manually curl it?

curl -i -X POST http://localhost:3000/attachments/images/cache/upload

from shrine.

imfaisalkh avatar imfaisalkh commented on May 21, 2024

Thanks for your reply. It is certainly a 404 status. I'm working on cloud IDE so you might want to check it yourself: https://shrine-imfaisal.c9users.io/

Running the curl command curl -i -X POST https://shrine-imfaisal.c9users.io/attachments/images/cache/upload gives following status:


HTTP/1.1 404 Not Found
content-type: application/json
content-length: 0
cache-control: no-cache
x-request-id: 5a4ba1aa-9bbf-4bac-bc78-20da71b3098b
x-runtime: 0.006039
server: WEBrick/1.3.1 (Ruby/2.3.0/2015-12-25)
date: Wed, 17 Aug 2016 12:04:39 GMT
X-BACKEND: apps-proxy

from shrine.

janko avatar janko commented on May 21, 2024

Hmm, can you share your config/routes.rb? Could you also set a before filter on the endpoint, to see if the request is hitting the app at all?

ImageUploader::UploadEndpoint.plugin :hooks
ImageUploader::UploadEndpoint.before { puts "CALLED" }
mount ImageUploader::UploadEndpoint, at: "/attachments/images"

from shrine.

imfaisalkh avatar imfaisalkh commented on May 21, 2024

I've added your's mentioned code in my routes.rb, now this file looks like this:

Rails.application.routes.draw do
  root to: 'photos#index'

  patch "/album" => "photos#update"
  post "/album/photos" => "photos#create"


  ImageUploader::UploadEndpoint.plugin :hooks
  ImageUploader::UploadEndpoint.before { puts "CALLED" }
  mount ImageUploader::UploadEndpoint, at: "/attachments/images"

end

As mentioned earlier, all other code (model, view, controllers) are based on this demo app: https://github.com/erikdahlstrand/shrine-rails-example

from shrine.

imfaisalkh avatar imfaisalkh commented on May 21, 2024

Yes, I meant to paste this link :)

So, I've updated the shrine gem to version 2.2.0 but it still not working. However, now it is returning 400 status instead of 404. Previous curl command now returns following status:

HTTP/1.1 400 Bad Request
content-type: application/json
content-length: 45
cache-control: no-cache
x-request-id: 62bf4930-a51d-475f-ba39-9a6df10d9d38
x-runtime: 0.006091
server: WEBrick/1.3.1 (Ruby/2.3.0/2015-12-25)
date: Wed, 17 Aug 2016 13:41:14 GMT
X-BACKEND: apps-proxy

{"error":"Missing query parameter: \"file\""}

file param seems to be missing.

from shrine.

janko avatar janko commented on May 21, 2024

(I closed the issue because this is now related to FineUploader.)

from shrine.

imfaisalkh avatar imfaisalkh commented on May 21, 2024

Ok, I'll look into it and thanks very much for your prompt support.

from shrine.

rnicholus avatar rnicholus commented on May 21, 2024

Fine Uploader, unfortunately, requires a JSON response to all upload requests due to support of IE9 and older, where the uploads are sent via form submits and the response status cannot be read client-side. Furthermore, returning a non-200 response in IE9 and older will cause problems as well (see the IE limitations section in the Fine Uploader docs for more info). v6.0 will likely contain an update to only require a JSON response for older browsers. See FineUploader/fine-uploader#1325 for more details.

from shrine.

rnicholus avatar rnicholus commented on May 21, 2024

Yes, that is unfortunately required due to the reasons detailed in my last post. If Fine Uploader only supported IE10+, none of this would be necessary. Luckily, in the future, the response requirements will be a bit more flexible.

from shrine.

imfaisalkh avatar imfaisalkh commented on May 21, 2024

@rnicholus So, I hope there is any method to modify the response to include the success property on server end untill the v6.0 is release of fineuploader.

from shrine.

rnicholus avatar rnicholus commented on May 21, 2024

I can't answer that question. @janko-m is probably the best person to ask. Note that if you do plan on supporting IE9 or older, you will need the JSON success property no matter what.

from shrine.

imfaisalkh avatar imfaisalkh commented on May 21, 2024

Yeah, I've opened up a ticket, let see what's possible. Thanks.

from shrine.

janko avatar janko commented on May 21, 2024

@nickooolas This is the issue that @imfaisalkh opened afterwards, and here is the middleware that you need to use in UploadEndpoint to add the success field.

Note that I will make this much easier in the future, as I plan to split out direct_upload plugin into upload_endpoint and presign_endpoint, so they will be able to have options for modifying the response (so that you don't have to do all this boilerplate like updating Content-Length header). But for now this middleware is the best way IMO.

from shrine.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.