-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
invalid byte sequence in UTF-8 when generating spreadsheet in Mailer #29
Comments
@tigershen23 Try passing xlsx = (render_to_string handlers: [:axlsx], formats: [:xlsx], template: "report", layout: false) Let me know if that helps. |
@straydogstudio no dice :(, same error. |
@tigershen23 A few people have had this error, and I've never been able to duplicate it. Is it possible for you to create a simple Rails app in a Github repo that duplicates the error? Perhaps a stripped down version of your application? |
@straydogstudio Yeah, I'll see what I can do. Do you know of a way to force encoding on the render itself? I've found some general solutions to error in Ruby/Rails (not for axlsx_rails specifically), but it seems like the |
@tigershen23 These can be hard errors to track down. Sorta vague. When I have time I will investigate forcing encoding in render to string. There was another issue that solved this problem with their smtp_settings and ActionMailer. I've no idea what you have, but it might be worth taking a look just in case. |
@straydogstudio yeah I saw that, I'm afraid of messing up other mailers by fiddling with those but I could try. Thanks! |
@tigershen23 By the way, another option instead of a github repo is to send me your Gemfile and describe your setup (including platform, versions, etc.) |
@tigershen23 A recent issue showed a possible solution. Make sure your template for the attachment does not have the same name as the mailer template. If you try it let me know if it works. |
I have not been able to reproduce this bug. But, based on the experience of others (here and in other issues) the latest release of axlsx_rails (0.5.0) explicitly sets layout to false. Advising others to set the layout to false appears to fix these issues. I am cautiously optimistic. Please try 0.5.0 and comment on this issue (or open another) if the failure happens again. |
I still have this issue
|
First I'd double check that your sidekiq job isn't receiving parameters that are messed up when it tries to run. E.g. binary data, or something like it. Passing parameters to sidekiq isn't always straight forward. Second, if you can create a stripped down repo with the error, that would be very helpful. I've never been able to reproduce it and have something to debug. I realize that takes time. |
Actually sidekiq just receives ID and then run mailer, and the mailer service do a report render csv or xlsx. |
Found what caused problem!
|
Excellent. I'm glad to hear it. I will update the README and any examples to make sure it is clear. We will find out if that helps. |
I'm reopening this issue until I can test the encoding. |
I've got a similar situation. I'm using I've triggered this bug a few times, particularly when rendering partials from within partials (though only in a small percentage of cases so I don't really know what's happening and it's very hard to debug). 2 funny things:
render template: '...', handlers: [...], formats: [...], locals: { ... } and that fails, but this one doesn't: [1].each do
render template: '...', handlers: [...], formats: [...], locals: { ... }
end and I've got no idea WHY. I also checked the data I'm rendering, and everything is valid UTF-8 (in fact, I tried it with different data). So I'm fairly certain that's not the problem. [1] https://gist.github.com/nachokb/f3cc995cf44acbfd0e63ee25515f4cb8 |
@nachokb Now that is an interesting solution. I've guessed it is a scope issue, though I've never been able to replicate the problem and test it. I agree, whatever this is, it is hard to debug. Thanks for sharing what you've found. |
Hi, I am getting same error.
|
Hi, I reset the database, the excel file to be created is empty and I still get an error. Here is my base64 attachment.
And this is decoded version
Isn't that awkward? |
I'm on Rails 5.2, and got the error in this issue - I got this working by calling the new #render method and omitting the base64 option in the mailer itself:
in JoeMailer:
|
I dont know if this is helping for others. I had problems sending xlsx attachment. I dont know the exact problem, but the file always corrupt (can't be opened). I use sendgrid. After 2 hours debugging, I found my root cause is the base64 encoding itself, ruby adds So I use |
@ksdputra Excellent work! I'll change the README (unless you want to do a PR for that.) That would definitely cause problems. |
I'm getting the "Excel cannot open the file ..." error. Rails 6.1 I was hoping the strict_encode64 was going to solve this, but it didn't. What I find strange is the file opens perfectly fine when I export using a link_to, but I'm unable to open the file when attaching to a mailer.
|
@dtakeshta try omitting the base64 argument or generally following my workaround detailed in my comment above from about a year ago. |
Hey there, I'm trying to attach an xlsx spreadsheet to a Sidekiq delayed email (only difference is that it's in the background), and I'm getting a
WARN: invalid byte sequence in UTF-8
that blows up the sending job. I've tried all manner of different encoding options for the output fromrender_to_string
, but no dice. This happens even when using very basic . The spreadsheet renders fine from the console and from a controller action. The email sends fine with no attachments. The following code is exactly what I'm running, with some names switched out. Gem version 0.3.0, Rails 4.1.7, Ruby 2.2.0report_mailer.rb
report.xlsx.axlsx
Output from a pry session right after the render_to_string call
Thanks in advance for your help.
The text was updated successfully, but these errors were encountered: