I use rails 3 and paperclip plugin to attach files.
I’ve got two models:
- Order;
- OrderAttachment:
- belongs_to :order;
- has_attached_file :doc;
And I try to attach files to order via paperclip;
When I’m attaching files with English or numeric file name everything works great:
SQL (0.0ms) INSERT INTO "order_attachments" ("order_id", "created_at", "updated_at", "doc_file_name", "doc_content_type", "doc_file_size", "doc_updated_at") VALUES (1, '2011-06-08 11:07:22.108523', '2011-06-08 11:07:22.108523', 'Example.txt', 'text/plain', 22, '2011-06-08 11:07:22.105523') RETURNING "id"
[paperclip] Saving attachments.
[paperclip] saving D:/my_project_path/public/system/docs/93/original/Example.txt
SQL (1.0ms) COMMIT
Completed 200 OK in 229ms (Views: 21.0ms | ActiveRecord: 7.0ms)
But when I’m attaching files with Russian file name error occurs:
SQL (1.0ms) INSERT INTO "order_attachments" ("order_id", "created_at", "updated_at", "doc_file_name", "doc_content_type", "doc_file_size", "doc_updated_at") VALUES (1, '2011-06-08 11:26:43.040925', '2011-06-08 11:26:43.040925', 'Пример.txt', 'text/plain', 26, '2011-06-08 11:26:43.035924') RETURNING "id"
[paperclip] Saving attachments.
[paperclip] saving D:/my_project_path/public/system/docs/94/original/Пример.txt
SQL (0.0ms) ROLLBACK
Completed in 161ms
Errno::ENOENT (No such file or directory - D:/my_project_path/public/system/docs/94/original/╨а╤Я╨б╨В╨а╤С╨а╤Ш╨а┬╡╨б╨В.txt):
app/controllers/orders_controller.rb:138:in `attachment'
Paperclip saves file to D:/my_project_path/public/system/docs/94/original/Пример.txt (i can open it via explorer) but no record in database created. Maybe something wrong with encoding.
I use:
- Windows 7 professional x64;
- PostgreSQL 9.0 (UTF-8 database encoding);
- Ruby 1.9.2;
- Ruby on Rails 3.0.7;
- Paperclip 2.3.11;
Thanks for any help.
As i said paperclip saves attached file and rails creates valid request, but something inside paperclip source goes frong under Windows.
Errno::ENOENT exception was caught in C:\Ruby192\lib\ruby\gems\1.9.1\gems\paperclip-2.3.11\lib\paperclip\storage\filesystem.rb source file in line 42
I changed this function to:
This solution works for me. Now sever log output is: