When i try to upload a file via a C# application, i always get an error from ror. Here is the error Mon Jul 16 12:58:51 +0800 2007: Error calling Dispatcher.dispatch #<EOFError: bad boundary end of body part> C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/cgi_multipart_eof_fix-2.1/lib/cgi_multipart_eof_fix.rb:106:in `read_multipart'' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/cgi_ext/raw_post_data_fix.rb:38:in `initialize_query'' C:/InstantRails/ruby/lib/ruby/1.8/cgi.rb:2275:in `initialize'' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/cgi.rb:50:in `initialize'' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/rails.rb:69:in `new'' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/rails.rb:69:in `process'' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:618:in `process_client'' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:617:in `each'' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:617:in `process_client'' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:in `run'' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:in `initialize'' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:in `new'' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:in `run'' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:720:in `initialize'' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:720:in `new'' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:720:in `run'' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/configurator.rb:271:in `run'' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/configurator.rb:270:in `each'' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/configurator.rb:270:in `run'' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/bin/mongrel_rails:127:in `run'' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/command.rb:211:in `run'' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/bin/mongrel_rails:243 C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:488:in `load'' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:488:in `load'' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:342:in `new_constants_in'' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:488:in `load'' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/servers/mongrel.rb:60 C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'' C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in `require'' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:342:in `new_constants_in'' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in `require'' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/server.rb:39 C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'' C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'' ./script/server:3 -e:4:in `load'' -e:4 I don''t know what is going on. And here is my c# code using System; using System.Collections.Generic; using System.Text; using System.Web; using System.Net; using System.IO; namespace ConsoleApplication13 { class Program { static void Main(string[] args) { Program test = new Program(); test.firstmethod(); } private void firstmethod() { string url = "http://localhost:3002/filelink/upload2"; string[] files = { "c:\\test.txt" }; string logpath = null; UploadFilesToRemoteUrl(url, files, logpath); } private void UploadFilesToRemoteUrl(string url, string[] files, string logpath) { long length = 0; string boundary = "----------------------------" + DateTime.Now.Ticks.ToString("x"); HttpWebRequest httpWebRequest2 (HttpWebRequest)WebRequest.Create(url); httpWebRequest2.ContentType = "multipart/form-data; boundary=" + boundary; httpWebRequest2.Method = "POST"; httpWebRequest2.KeepAlive = true; httpWebRequest2.Credentials System.Net.CredentialCache.DefaultCredentials; Stream memStream = new System.IO.MemoryStream(); byte[] boundarybytes2 System.Text.Encoding.ASCII.GetBytes("--" + boundary + "\r\n"); byte[] boundarybytes System.Text.Encoding.ASCII.GetBytes("\r\n--" + boundary + "\r\n"); memStream.Write(boundarybytes2,0,boundarybytes2.Length); length += boundarybytes2.Length; string headerTemplate = "Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\n Content-Type: application/octet-stream\r\n\r\n"; for(int i=0;i<files.Length;i++) { string header string.Format(headerTemplate,"any_file",files[i]); byte[] headerbytes System.Text.Encoding.UTF8.GetBytes(header); memStream.Write(headerbytes,0,headerbytes.Length); length += headerbytes.Length; FileStream fileStream = new FileStream(files[i], FileMode.Open, FileAccess.Read); byte[] buffer = new byte[1024]; int bytesRead = 0; while ( (bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0 ) { memStream.Write(buffer, 0, bytesRead); length += bytesRead; } memStream.Write(boundarybytes,0,boundarybytes.Length); length += boundarybytes.Length; fileStream.Close(); } httpWebRequest2.ContentLength = memStream.Length; Stream requestStream = httpWebRequest2.GetRequestStream(); memStream.Position = 0; byte[] tempBuffer = new byte[memStream.Length]; memStream.Read(tempBuffer,0,tempBuffer.Length); memStream.Close(); requestStream.Write(tempBuffer,0,tempBuffer.Length ); requestStream.Close(); WebResponse webResponse2 = httpWebRequest2.GetResponse(); Stream stream2 = webResponse2.GetResponseStream(); StreamReader reader2 = new StreamReader(stream2); Console.WriteLine(reader2.ReadToEnd()); webResponse2.Close(); httpWebRequest2 = null; webResponse2 = null; } } } Here is My ruby on rails code class FilelinkController < ApplicationController require "ftools" scaffold :filelink def index redirect_to :action => "list" end def list @filelink = Filelink.find_all end def uploads link = String.new() @link = Date.today().strftime("%d_%m_%y").to_s() @filelink = Filelink.new() @filelink[''patientname''] = @params[''patientname''] @filelink[''filelink''] = "#{RAILS_ROOT}/public/file/"+@link+".txt" File.open(@filelink[''filelink''], "wb") { |f| f.write(@params[''any_file''].read) } #do |f| #f.write(@params[''any_file''].read) #end @filelink.save redirect_to :action => "list" end ###The Used Part def upload2 if File.size?(@params[''any_file''])>0 File.open("#{RAILS_ROOT}/public/file/try.txt", "wb") do |f| f.write(@params[''any_file''].read) end else redirect_to :action =>"list" end redirect_to :action =>"list" end ##### end And here is the form <html> <head> <b><title>Upload file form</title></b> </head> <body> <h1><b>Add a patient records</b></h1> <form action="/filelink/upload2" name = "newrecord" method="POST" enctype="multipart/form-data"/> <p><label>The HeartBeat file <b>:</b></label><br/><input type="file" name="any_file" accept = "text/plain" /></p> <br/> <input type="submit" name="Upload" value = "upload"/> </form> </body> </html> For more information, i use Aptana as the development platform of ror, and i use visual studio.net 2005 as the c# development platform. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---