Mensajes de error de plupload

I'm using Plupload with a rails app. The uploader allows users to submit images, but I require that the images be greater than a certain minimum pixel size. This is validated on the server side when processing an image received from Plupload.

Now, the uploader is working fine, but when a particular file fails the user sees an orange triangle and if they hover over it they get "HTTP error." That is pretty useless for the average user.

This is what I have in my rails controller right now:

def create
    @photo = current_user.photos.new(:image => params[:file])
    if @photo.save
        head :ok
    else
        head :bad_request
    end
end

How can I pass back the descriptive error messages from my application to Plupload so they can be displayed to the user in that orange triangle?

Do I need to return some json or xml, or something different? I've experimented with returning different representations of the failed image object, but so far nothing I've done has gotten my error messages picked up by Plupload.

¡Agradezco cualquier ayuda!

preguntado el 27 de agosto de 11 a las 21:08

Did you ever find a solution to this? I am receiving the same Http Error when server-side errors occur, except I am using .NET. -

Nope, never found a workaround for it and quit using Plupload. -

1 Respuestas

Multiple upload carrierware plupload

 #app/controllers/adm/galerias_imagem.rb
    class Adm::GaleriasImagensController < ApplicationController
    layout "adm_layout"
    ....
     def create

      @adm_galerias_imagem = Adm::GaleriasImagem.new(adm_galerias_imagem_params)
        respond_to do |format|
          if @adm_galerias_imagem.save   
              head :ok
        else
            head :bad_request         
        end
      end

#app/views/adm/galerias_imagens/new.html.erb
<div id="filelist">Your browser doesn't have Flash, Silverlight or HTML5 support.</div>
<br />

<div id="container">
<a id="pickfiles" href="javascript:;">[Select files]</a> 
<a id="uploadfiles" href="javascript:;">[Upload files]</a>
</div>


<%= link_to 'Back', adm_galerias_imagens_path, class: "btn btn-default" %>

<% content_for :js do %>
$(function(){
  var uploader = new plupload.Uploader({
    runtimes : 'html5,flash,silverlight,html4',
    browse_button : 'pickfiles', // you can pass in id...
    container: document.getElementById('container'), // ... or DOM Element itself
    url : '<%= adm_galerias_imagens_path %>',
    multipart: true,
    max_file_size : '10mb',
    multipart_params: {
      "authenticity_token" : "<%= form_authenticity_token %>",
      '<%= Rails.application.config.session_options[:key] %>': '<%= request.session_options[:id] %>',
      "adm_galerias_imagem[galeria_id]": <%= params[:id] %>
    },
    flash_swf_url : '/assets/Moxie.swf',
    silverlight_xap_url : '/assets/Moxie.xap',
    file_data_name:"adm_galerias_imagem[imagem]",
    filters : {
      max_file_size : '10mb',
      mime_types: [
      {title : "Image files", extensions : "jpg,gif,png"},
      {title : "Zip files", extensions : "zip"}
      ]
    }
  });
uploader.bind('Init', function(up, params) {
  $('#filelist').html("<div>Current runtime: " + params.runtime + "</div>");
});
uploader.bind('FilesAdded', function(up, files) {
  $.each(files, function(i, file) {
    $('#filelist').append(
      '<div id="' + file.id + '">' +
      'File: ' + file.name + ' (' + plupload.formatSize(file.size) + ') <b></b>' +'</div>'
      );
});
});
uploader.bind('UploadProgress', function(up, file) {
  $('#' + file.id + " b").html(file.percent + "%");
});
$('#uploadfiles').click(function(e) {
  uploader.start();
  e.preventDefault();
});
uploader.init();
});
<% end %> 

#app/views/layouts/adm_layout.html.erb

    <!--Scripts-->
        <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
        <script type="text/javascript">
            <%= yield :js %>
        </script>

Respondido 28 Jul 14, 05:07

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.