Comments (16)
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.
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.
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.
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.
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.
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.
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.
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.
(I closed the issue because this is now related to FineUploader.)
from shrine.
Ok, I'll look into it and thanks very much for your prompt support.
from shrine.
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.
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.
@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.
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.
Yeah, I've opened up a ticket, let see what's possible. Thanks.
from shrine.
@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)
- Download Endpoint returns http 500 for invalid urls
- 308 redirect HOT 1
- Plugin: "remove_invalid" doesn't clear _data column. HOT 5
- Shrine upload_endpoint on Sinatra 400 Bad Request HOT 2
- [Bug]: Error occurred when attempting to extract image dimensions: #<FastImage::UnknownImageType: FastImage::UnknownImageType> HOT 8
- [Bug]: Corruption of downloaded files when using `net-protocol v0.2.0` HOT 16
- [Bug]: Fix for bytesize on Array doesn't work when aws-core is installed from debian HOT 5
- [Bug]: remove_attachment error with ruby 3.2 HOT 2
- [Bug]: upload_options plugin moves file from store to cache HOT 2
- [Bug]: NoMethodError (undefined method 'bucket' for nil:NilClass) HOT 1
- [Bug]: no _dump_data is defined for class Proc (Shrine with Rails Cache) HOT 1
- [Bug]: `create_derivatives` uploads files already in the store HOT 2
- Website search broken after migrating to Docusaurus v2
- Support retries with remote_url HOT 1
- Unpermitted parameter: :images with dropzonejs HOT 4
- Specifying host: with plugin :url_options has no effect on the returned URL HOT 5
- Disabling cache is tricky HOT 2
- [Bug] File not promoted on permanent storage if reload the model inside a transaction HOT 4
- Using Shrine with Cloudflare R2 causes error Aws::S3::Errors::NotImplemented - x-amz-tagging HOT 5
- Documentation for `image_url` options HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from shrine.