Exception when trying to upload file from Flex to Rails (using paperclip)

岁酱吖の 提交于 2019-11-29 08:16:37
Tam

After pulling my hair for quite some time. I realized the problem was very silly!

I put a debug code inside the Paperclip pluging (Right where the backtrace is stating error:

vendor/plugins/paperclip/lib/paperclip/iostream.rb:8:in `extname'

and I noticed a line like this

name = respond_to?(:original_filename) ? original_filename : (respond_to?(:path) ? path : "stream")

After printing out some debug variables I realized that original_filename is nil which shouldn't be as it should be the actual file name uploaded to the server which is supposed to be doodle.png according to my code. Just to find out that I forgot one space before 'filename' in the data I was sending. So my code:

'Content-Disposition: form-data; name="{1}[photo]";' +  
                     'filename="{0}"' + lf +                         
                     'Content-Type: application/octet-stream' + lf + lf

is Wrong. This code:

'Content-Disposition: form-data; name="{1}[photo]"; ' +  //note extra space added here
                     'filename="{0}"' + lf +                         
                     'Content-Type: application/octet-stream' + lf + lf 

Works. That's it!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!