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
5
  • maybe you need this stackoverflow.com/questions/9607554/… Commented Nov 16, 2012 at 10:05
  • 2
    Have you tried using a magic comment at the top of the file: # Encoding: utf-8. Commented May 19, 2013 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. Commented Jun 7, 2013 at 9: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. Commented Jun 29, 2013 at 14:21
  • May be it is an error uploading the image did you add :multipart => true to the form? Commented Sep 5, 2013 at 8:11

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.