3

I am getting this error when trying to pass in an image:

!! Unexpected error while processing request: invalid byte sequence in UTF-8

The weird thing is that the raise (as below) did not get executed.

My question is: how can this happen to cause this error? Has it got anything to do with the headers or the params?

Any help here will be appreciated.

  def create
    raise "request did get executed in code here"
    debugger
    @asset = nil
    if params && params[:asset]
      p = params[:asset]
      if p[:file]
        user_id = p[:user_id] || current_user.try(:id)
        checksum = p[:checksum] || Util.file_checksum(p[:file].path)
        if user_id.present? && checksum.present?
          options = {:taken_at => p[:taken_at] || Util.file_taken_at(p[:file].path)}
          @asset = Asset.create user_id, checksum, p[:file], p[:file].original_filename, options
        end
      end
    end

    respond_to do |format|
      if @asset && @asset.state != QueueItem::STATE_NONE
        format.html { head :no_content }
        format.json { render :json => @asset, :status => :created }
      else
        format.html { head :no_content }
        format.json { render :json => @asset.try(:errors), :status => :unprocessable_entity }
      end
    end
  end
  • maybe you need this http://stackoverflow.com/questions/9607554/ruby-invalid-byte-sequence-in-utf-8 – Thanh Nov 16 '12 at 10:05
  • 2
    Have you tried using a magic comment at the top of the file: `# Encoding: utf-8`. – Kris May 19 '13 at 20:19
  • Old question, but I think i already had this kind of issue with Webrick. If you're using Webrick, try to use unicorn. – Arkan Jun 07 '13 at 09:02
  • Did your client send chunked request? Chunked requests are sended by binary parts so your ruby web-server cann't parse entire request and fall back with this exception. – Viacheslav Molokov Jun 29 '13 at 14:21
  • May be it is an error uploading the image did you add :multipart => true to the form? – rhernando Sep 05 '13 at 08:11

1 Answers1

0

Set the very first line in your controller with this : #encoding: UTF-8