transloadit / rails-sdk Goto Github PK
View Code? Open in Web Editor NEWTransloadit's official Rails SDK, maintained by the community
Home Page: https://transloadit.com/
License: MIT License
Transloadit's official Rails SDK, maintained by the community
Home Page: https://transloadit.com/
License: MIT License
Transloadit supports SHA-384 signatures, that what we should use considering SHA-1 vulnerabilities.
rails-sdk/lib/transloadit/rails/engine.rb
Line 86 in 4283e5d
Going from the example in the README:
<%= form_tag 'http://api2.transloadit.com/assemblies', :html => { :id => 'upload' } do |form| %>
<%= transloadit :s3_store %>
<%= form.label :file, 'File to upload' %>
<%= form.file_field :file %>
<%= form.submit %>
<% end %>
<%= transloadit_jquerify :upload %>
I get undefined method 'transloadit' for #<#<Class:0x000000011aadc8>:0x00000005ebd840>
.
on Rails 3.2.8
Im trying to use notify_url
#config/transloadit.yml auth: key : ... secret : ... duration: 1800 # 30 minute validity period for signed upload forms notify_url: http://...../callback templates: image_video: ...
But, the output generated by <%= transloadit :image_video %> doesn't include notify_url param
Sorry, it was just an undocumented use case, in the view:
<%= transloadit :image_video, :notify_url=>'http://someurl' %>
works
Users should be able to edit their transloadit config without having to restart the server during development.
Transloadit returns a JSON response that should be converted to a Rails-style HashWithIndifferentAccess automatically. Figure out how to do this, and do it.
Since Travis isn't usable for open source anymore.
When we are done, we should also update the badge at https://transloadit.com/docs/#sdks by adding this frontmatter to the rails-sdk integration file:
ghactions_workflow: Rails SDK CI # assuming that becomes the github actions workflow name
I tried putting max_size in the transloadit.yml file like this:
auth:
key : '418...'
secret : '660...'
duration: 1800 # 30 minute validity period for signed upload forms
max_size: 2097152
templates: ...
I can't get it to work. According to the Authentication page in the docs
You need to use max_size in the hidden params field of your form.
I've tried adding a hidden field in the form named "max_size" but it doesn't work either.
Is there a way to set a maximum file size?
Hi,
I just merged #10 from my friend Robin who is using the gem for a very big project. His changes made sense to me so I went ahead, but please feel free to comment.
If things look reasonable, could you please publish a new version of the gem? If there is a way to make it possible for me to do that as well, that'd be great.
--fg
Using this gem with Rails 3.2 results in:
DEPRECATION WARNING: ActiveSupport::Memoizable is deprecated and will be removed in future
releases, simply use Ruby memoization pattern instead. (called from <top (required)>
at .../config/application.rb:11)
it looks like it should be simple to replace the memoize :configuration
call with a bit of @configuration
cachery.
in view_helper.rb method options_to_json, onfileselect is not in the callback array
Hi,
I tried to call transloadit_jquerify
method while defining onError
and onCancel
callbacks, like this:
<%= transloadit_jquerify :video_form, wait: false, processZeroFiles: false,
onCancel: "function() { console.log('Entered on cancel'); }",
onError: "function() { console.log('Entered on error'); }" %>
but it did not work. The generated script was like this:
<script type="text/javascript">
//<![CDATA[
jQuery(function($) {
var script = '//assets.transloadit.com/js/jquery.transloadit2-latest.js';
$.getScript(script, function() {
$('#video_form')
.attr('enctype', 'multipart/form-data')
.transloadit({"wait": false,
"processZeroFiles": false,
"onCancel": function() {console.log('Entered on cancel'); },
"onError": function() { console.log('Entered on error'); }});
});
});
//]]>
</script>
I figured out that the problem's with the "onCancel"
and "onError"
being strings. When I wrote the generated script manually and removed the double quotes it all worked well.
Also there's not much documentation regarding how to use callback functions with transloadit_jquerify
. I had to take a look at the code to see how you guys expect callbacks to be provided.
I'm trying to update my transloadit templates to use some more dynamic fields from the html form (Rails, Rackspace cloud files, transloadit_jquerify etc), however the fields
object doesn't seem to contain the values I'm passing.
The template is set up like this:
store:
use: ['optimized']
robot: '/cloudfiles/store'
container: *rs_container
user: *rs_user
key: *rs_key
data_center: *rs_data_center
account_type: *rs_account_type
path: "images/${fields.item_category}/${file.id}_${file.url_name}"
and my HTML form contains the following:
<%= form_for item, :url => form_url, :html => { :id => 'upload_image' } do |form| %>
<%= transloadit :image_upload %>
<%= form.label :file, 'File to upload' %>
<%= form.file_field :file, :accept => "image/jpg, image/jpeg, image/png" %>
<%= form.label :name, "Description" %>
<input type="text" name="name" id="name"/>
<!-- I have tried both options for creating a hidden field -->
<%= form.hidden_field 'item_category', :value => item_category %>
<input type="hidden" name="item_category" id="item_category" value="<%= item_category %>" />
<%= form.submit 'Upload Image', :id => "submitBtnImage" %>
<% end %>
<%= transloadit_jquerify :upload_image, :wait => true, :processZeroFiles => false %>
But the item_category
is always empty or nil, resulting in a file path like images//XXX_file.jpg
Any ideas what I'm doing wrong here?
In Issue #3 you state you can pass arguments correctly. However, if I want to add a callback function such as :onResult => "my_function() { alert('do stuff') }"
, the resulting javascript ends up looking like:
"onResult": "my_function() { alert('do stuff') }"
onResult()
is a string (rather than a function) and thus, not actually executed. It seems this happens because you parse the options using to_json, which would convert any Javascript code into a string rather than pass it straight through. Am I missing something here? Is there a better way to do this using your gem?
Rails 3.1 already does this with file_field, so we shouldn't have code to do this ourselves.
Is there any way to do i18n with the transloadit-rails gem?
Currently these helpers result in a form that is valid for 5 minutes. Thats quite rough.
Case: User comes to form. Spends 10 minutes on finding 5 photos to upload. Hits upload -> suddenly the upload is invalid because form was valid only 5 minutes.
I'd need the follow to work:
<%= transloadit :upload_basics, {:auth => [:expires => 1.hour.from_now]} %>
Easiest would be to change view_helper to change the hash auth params before signing it. More clearlier fix would be to change how ruby-sdk work and change this one accordingly.
I am trying get a video out as a mp4 and I need to keep the original proportions.
This is my current Template
{
"steps": {
"encode": {
"use": ":original",
"robot": "/video/encode",
"ffmpeg_stack": "v2.2.3",
"result": true,
"preset": "ipad-high",
"ffmpeg_params": {
"s": "-1x-1"
}
},
"thumbnails": {
"use": ":original",
"robot": "/video/thumbs"
},
"store": {
"use": "encode",
"robot": "/s3/store",
"key": "xxxxxxxxxxx",
"secret": "xxxxxxxxxxx",
"bucket": "xxxxxxxxxxx"
}
}
}
Should be loaded from //assets.transloadit.com/js/jquery.transloadit2.js
Hi,
I've been trying to make the /file/filter robot work with my rails app and failing.
I haven't found any useful ruby on rails examples in the Transloadit docs.
I would like some help on how to use the /file/filter robot to decline a file larger than 10MB using ruby on rails.
Thank you
I assume this can be done already, but there should be an example for setting things like wait: true
.
The default jQuery SDK version in transloadit.yml
file is v2-latest
but v3-latest
is available.
As per jquery SDK readme v3-latest
is the recommended version to use
Hello,
I am using Rails 3.1
transloadit-rails gem version 1.0.2
I tried to use the transloadit-rails gem by following the tutorial for rails-sdk. Can anyone help me?
This is the error log
[2011-10-19 15:47:06] ERROR NameError: uninitialized constant Transloadit::Rails::ViewHelper
/Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/transloadit-rails-1.0.0/lib/transloadit/rails/engine.rb:21:in `block (2 levels) in <class:Engine>'
/Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.1/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
/Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.1/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
/Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.1/lib/active_support/lazy_load_hooks.rb:43:in `block in run_load_hooks'
/Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.1/lib/active_support/lazy_load_hooks.rb:42:in `each'
/Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.1/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks'
/Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.1.1/lib/action_view/base.rb:216:in `<class:Base>'
/Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.1.1/lib/action_view/base.rb:133:in `<module:ActionView>'
/Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.1.1/lib/action_view/base.rb:8:in `<top (required)>'
/Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.1.1/lib/abstract_controller/view_paths.rb:90:in `view_paths='
/Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.1.1/lib/abstract_controller/view_paths.rb:76:in `prepend_view_path'
/Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.1/lib/rails/engine.rb:532:in `block (2 levels) in <class:Engine>'
/Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.1/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
/Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.1/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
/Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.1/lib/active_support/lazy_load_hooks.rb:43:in `block in run_load_hooks'
/Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.1/lib/active_support/lazy_load_hooks.rb:42:in `each'
/Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.1/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks'
/Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.1.1/lib/action_controller/base.rb:234:in `<class:Base>'
/Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.1.1/lib/action_controller/base.rb:171:in `<module:ActionController>'
/Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.1.1/lib/action_controller/base.rb:3:in `<top (required)>'
/Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.1.1/lib/action_dispatch/middleware/static.rb:31:in `ext'
/Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.1.1/lib/action_dispatch/middleware/static.rb:15:in `match?'
/Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.1.1/lib/action_dispatch/middleware/static.rb:47:in `call'
/Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.1/lib/rails/engine.rb:456:in `call'
/Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.1/lib/rails/rack/content_length.rb:16:in `call'
/Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.1/lib/rails/rack/log_tailer.rb:14:in `call'
/Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/rack-1.3.5/lib/rack/handler/webrick.rb:59:in `service'
/Users/weyewe/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
/Users/weyewe/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
/Users/weyewe/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
I followed the tutorial but can't get the form to submit without getting the aforementioned alert. After I click "ok", Transloadit quickly throws INVALID_FORM_DATA: bad form data, cannot parse
.
My app is using Rails 4.1.4
and jquery-rails 2.1.4
.
Here's my form:
= form_for @profile, url: community_add_photo_path(@profile), html: {id: 'photo_form'} do |f|
= render 'shared/error_messages', object: f.object
= transloadit :profile_photo
= hidden_field_tag 'transloadit_template', 'profile_photo'
%table.list
%tr
%td.faded.label Photo Filename
%td= f.file_field :photo, required: true
%tr
%td
%td= f.submit 'Upload'
= transloadit_jquerify :photo_form, wait: true
And my transloadit.yml
file:
development:
jquery_sdk_version: 'latest'
auth:
key: 'key'
secret: 'secret'
duration: 1800 # 30 minute validity period for signed upload forms
templates:
profile_photo:
steps:
resize:
height: 256
resize_strategy: 'fillcrop'
robot: '/image/resize'
width: 256
store:
bucket: 'bucket-name'
key: 'key'
path: 'temp/${assembly.id}/${file.name}'
robot: '/s3/store'
secret: 'secret'
Any suggestions? Thanks!
before_filter
has been deprecated since Rails 5.1 in favor of before_action
, so at least module Transloadit::Rails::ParamsDecoder
which is referenced in the README should be updated to play nice also with recent/updated applications.
The JSON response is not parsed automatically by the controller ( RoR 3.1)
It return a string that I have to parse with JSON.parse(params[:transloadit])
https://github.com/transloadit/rails-sdk/#usage
There is no transloadify
helper.
Something went wrong when loading my config, and I got:
NoMethodError in Uploads#index
Showing /Users/felix/Desktop/transloadit-test/app/views/uploads/index.html.erb where line #2 raised:
You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.[]
Extracted source (around line #2):
1: <%= form_for :thing, :html => { :id => 'upload' } do |form| %>
2: <%= form.transloadit :my_template %>
3: <%= form.file_field :file, 'File to upload' %>
4: <% end %>
5:
Rails.root: /Users/felix/Desktop/transloadit-test
Turning this into a more helpful message would be great.
Thanks for your work on this gem :)
rails-sdk has dependency on 'mime-types', '~> 2.99'
Rails 5 depends on mime-types (3.1)
Can you loosen the dependency so rails-sdk can be used in a Rails 5 app?
i.e. the transloadit.yml file should look like:
production:
development:
...
Paperclip is pretty ubiquitous. It'd be nice to integrate support with it. There will likely be multiple use-cases:
transloadit_id
in the pathtransloadit_id
rails-sdk / app / helpers / transloadit_helper.rb file needs fixes. (https://github.com/transloadit/rails-sdk/blob/master/app/helpers/transloadit_helper.rb)
Dollar sign is also used by other libraries, so you can't trust that its reserved for jquery: http://docs.jquery.com/Plugins/Authoring
(Yeah, I'm slowly migrating from prototype to jquery)
transloadit_helper.rb produces following:
$(function() {
CODE INSIDE HERE
});
It should be:
(function($) {
CODE INSIDE HERE
}(jQuery));
So the total helper would be:
def transloadit_jquerify(id, options = {})
javascript_tag %{
(function($) {
var script = '//assets.transloadit.com/js/jquery.transloadit2.js';
$.getScript(script, function() {
$('##(id)')
.attr('enctype', 'multipart/form-data')
.transloadit({wait: true, fields: true});
});
}(jQuery));
}
end
transloadit-rails works great for me using jquery-rails 2.1.3 (which uses JQuery 1.8.2). But it doesn't work with jquery-rails 2.2.1 (JQuery 1.9.1). The symptom is that the form submit doesn't seem to get intercepted anymore - the form gets posted straight to my server.
Let me know if this is jquery-sdk's fault and I'll move this issue over.
My app is using ruby 1.8.7 and rails 2.3.5. Does the current version of rails-sdk support rails 2.3? If it is not, could you give me a link of older version which compatible with rails 2.3?
A user playing around with the rails example had this to say
The Rails example you have does not include any information about how to save the uploaded file information to the database for later usage. I can see the information can be taken from some params, but to me the documentation seems very confusing there - params[:transloadit][:results][:resize].first[:url] - how does this adapt to different Transloadit templates? How can I get the information on the form itself before submitting it?
A good way to solve this may be to have the example display a formatted JSON tree of the assembly response.
From installing rails to uploading and resizing an image and displaying the results.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.