Rails Amazon S3 direct upload with JQuery File Uploader -


i have spent days trying make work. getting error

options https://bucketname.s3.oregon.amazonaws.com/ net::err_name_resolution_failed

i using version 43.0.2357.130 ubuntu 14.04 (64-bit)

gemfile:

gem "jquery-fileupload-rails" gem 'aws-sdk' 

application.js (after jquery):

//= require jquery-fileupload/basic 

application.css:

 *= require jquery.fileupload  *= require jquery.fileupload-ui 

i have model called uploads have generated scaffolds this:

rails generate scaffold upload upload_url:string 

uploads_controller.rb:

def new   @s3_direct_post = aws::s3::presignedpost.new(aws::credentials.new(env['aws_s3_access_key_id'], env['aws_s3_secret_access_key']),                                                  "oregon", env['aws_s3_bucket'], {                                                 key: '/uploads/object/test.test',                                                 content_length_range: 0..999999999,                                                 acl: 'public-read',                                                 success_action_status: "201",                                               })   @upload = upload.new end 

_form.html.erb (for uploads):

<%= form_for(@upload, html: { class: "directupload" }) |f| %> ...... <div class="field">   <%= f.label :upload_url %><br>   <%= f.file_field :upload_url %> </div> ...... <%= content_tag "div", id: "upload_data", data: {url: @s3_direct_post.url, form_data: @s3_direct_post.fields } %> <% end %> 

application.js (in end):

$( document ).ready(function() {         $(function() {       $('.directupload').find("input:file").each(function(i, elem) {         var fileinput    = $(elem);         var form         = $(fileinput.parents('form:first'));         var submitbutton = form.find('input[type="submit"]');         var progressbar  = $("<div class='bar'></div>");         var barcontainer = $("<div class='progress'></div>").append(progressbar);         fileinput.after(barcontainer);         fileinput.fileupload({           fileinput:       fileinput,           url:             $('#upload_data').data('url'),           type:            'post',           autoupload:       true,           formdata:         $('#upload_data').data('form-data'),           paramname:        'file', // s3 not nested name fields i.e. name="user[avatar_url]"           datatype:         'xml',  // s3 returns xml if success_action_status set 201           replacefileinput: false,           progressall: function (e, data) {             var progress = parseint(data.loaded / data.total * 100, 10);             progressbar.css('width', progress + '%')           },           start: function (e) {             submitbutton.prop('disabled', true);              progressbar.               css('background', 'green').               css('display', 'block').               css('width', '0%').               text("loading...");           },           done: function(e, data) {             submitbutton.prop('disabled', false);             progressbar.text("uploading done");              // extract key , generate url response             var key   = $(data.jqxhr.responsexml).find("key").text();              // create hidden field             var input = $("<input />", { type:'hidden', name: fileinput.attr('name'), value: url })             form.append(input);           },           fail: function(e, data) {             submitbutton.prop('disabled', false);              progressbar.               css("background", "red").               text("failed");           }         });       });     });     }); 

seriously can fix this?

my guess have misconfigured bucket name / route. error comes amazon, warning there no dns route https://bucketname.s3.oregon.amazonaws.com/.

it seems me need set actual bucketname bucket name, , drop oregon url. given bucket named aymansalah, url be: https://aymansalah.s3.amazonaws.com/

review aws::credentials documentation , check environment variables achieve url.


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

qt - Passing a QObject to an Script function with QJSEngine? -

c# - Web API response xml language -