tag:blogger.com,1999:blog-4911618396957689392.post6909376501999577082..comments2018-03-13T10:19:22.446-07:00Comments on RubyizednRailified: Multipart form data post through ruby scriptAmit Kumarhttp://www.blogger.com/profile/07178616519676182700noreply@blogger.comBlogger15125tag:blogger.com,1999:blog-4911618396957689392.post-56671549935475162072011-04-01T13:43:30.725-07:002011-04-01T13:43:30.725-07:00Thanks for the detailed analysis. It would be inte...Thanks for the detailed analysis. It would be interesting to know if "CR LF" would drop the submitted form data. I would try to replicate this. In the meantime, please send me some log statements and means to replicate it. This would save me some extra hours.<br /><br />Thanks!Amit Kumarhttps://www.blogger.com/profile/07178616519676182700noreply@blogger.comtag:blogger.com,1999:blog-4911618396957689392.post-68096728133588451902011-04-01T11:16:34.966-07:002011-04-01T11:16:34.966-07:00Actually I don't see an error message. I was u...Actually I don't see an error message. I was using ruby-multipart-post to post a form to a legacy web application. My form had only text fields and no files. I observed that the web app would consistently reject the last form element because it had an extraneous "CR LF" appended to value of the last from element. I researched a little and found that lines of data in a multipart form are separated by a CR LF. With ruby-multipart-post there seems to an excess "CR LF" sequence after the last text field value and before the form boundary. I can send you some of my application logs and ethereal traces of a working and non-working post. The working post was done from a browser and the non working post using the gem. I'll do this later in the day or sometime tomorrow.<br />But do you think there could be some sense in my theory?<br /><br />-AbhiAbhihttps://www.blogger.com/profile/01270973454609026559noreply@blogger.comtag:blogger.com,1999:blog-4911618396957689392.post-30401290562343328012011-04-01T11:13:46.569-07:002011-04-01T11:13:46.569-07:00This comment has been removed by the author.Abhihttps://www.blogger.com/profile/01270973454609026559noreply@blogger.comtag:blogger.com,1999:blog-4911618396957689392.post-57629791349585809302011-04-01T10:20:46.106-07:002011-04-01T10:20:46.106-07:00strangely that has been working for me
do you get ...strangely that has been working for me<br />do you get error?<br />can you post stack trace ?Amit Kumarhttps://www.blogger.com/profile/07178616519676182700noreply@blogger.comtag:blogger.com,1999:blog-4911618396957689392.post-49124077573221513252011-04-01T08:18:54.328-07:002011-04-01T08:18:54.328-07:00Hey Amit,
Just wondering if the last changes I m...Hey Amit, <br /><br />Just wondering if the last changes I made make sense? Would you consider updating the gem?<br /><br />-AbhiAbhihttps://www.blogger.com/profile/01270973454609026559noreply@blogger.comtag:blogger.com,1999:blog-4911618396957689392.post-36156532578026163032011-03-28T17:21:31.113-07:002011-03-28T17:21:31.113-07:00Hey Amit,
I had to make another minor modificati...Hey Amit, <br /><br />I had to make another minor modification to get this work for me. <br />The diff is shown below. I had to remove the first "\r\n" on line 26. They are probably unnecessary.<br />Let me know if this makes sense. <br /><br /><br />*** multi_part_post.rb.org 2011-03-25 06:56:37.000000000 +0000<br />--- multi_part_post.rb 2011-03-25 06:57:35.000000000 +0000<br />***************<br />*** 23,29 ****<br /> @parts << Parts::StringParam.new("--#{multi_part_boundary}\r\n" + "Content-Disposition: form-data; name=\"#{key}\"\r\n" + "\r\n" + "#{val}\r\n")<br /> end<br /> end<br />! @parts << Parts::StringParam.new( "\r\n--" + multi_part_boundary + "--\r\n" )<br /> end<br /> <br /> def multi_part_boundary<br />--- 23,29 ----<br /> @parts << Parts::StringParam.new("--#{multi_part_boundary}\r\n" + "Content-Disposition: form-data; name=\"#{key}\"\r\n" + "\r\n" + "#{val}\r\n")<br /> end<br /> end<br />! @parts << Parts::StringParam.new( "--" + multi_part_boundary + "--\r\n" )<br /> end<br /> <br /> def multi_part_boundaryAbhihttps://www.blogger.com/profile/01270973454609026559noreply@blogger.comtag:blogger.com,1999:blog-4911618396957689392.post-58951907412158814622011-03-23T10:46:05.122-07:002011-03-23T10:46:05.122-07:00@abhi Thanks for the suggestion. Making change in ...@abhi Thanks for the suggestion. Making change in the gem.Amit Kumarhttps://www.blogger.com/profile/07178616519676182700noreply@blogger.comtag:blogger.com,1999:blog-4911618396957689392.post-17675436179879462582011-03-22T20:46:18.967-07:002011-03-22T20:46:18.967-07:00Hey Amit,
I had to make a few changes to get this...Hey Amit,<br /><br />I had to make a few changes to get this working for me. Here is the diff. Let me know if this makes sense. <br /><br /><br />*** multi_part_post.rb.org 2011-03-22 08:49:53.000000000 -0700<br />--- multi_part_post.rb 2011-03-22 20:30:58.000000000 -0700<br />***************<br />*** 33,45 ****<br /> def submit(to_url, query_string=nil)<br /> post_stream = Stream::MultiPart.new(@parts)<br /> url = URI.parse( to_url )<br />! post_url_with_query_string = "#{url.path}?#{query_string}"<br /> req = Net::HTTP::Post.new(post_url_with_query_string, @request_headers)<br /> req.content_length = post_stream.size<br /> req.content_type = 'multipart/form-data; boundary=' + multi_part_boundary<br /> req.body_stream = post_stream<br />! req.use_ssl = true if url.scheme == "https"<br />! res = Net::HTTP.new(url.host, url.port).start {|http| http.request(req) }<br /> <br /> #close all the open hooks to the file on file-system<br /> @streams.each do |local_stream|<br />--- 33,49 ----<br /> def submit(to_url, query_string=nil)<br /> post_stream = Stream::MultiPart.new(@parts)<br /> url = URI.parse( to_url )<br />! post_url_with_query_string = "#{url.path}"<br />! unless query_string.nil?<br />! post_url_with_query_string = post_url_with_query_string + "?#{query_string}"<br />! end <br /> req = Net::HTTP::Post.new(post_url_with_query_string, @request_headers)<br /> req.content_length = post_stream.size<br /> req.content_type = 'multipart/form-data; boundary=' + multi_part_boundary<br /> req.body_stream = post_stream<br />! http_handle = Net::HTTP.new(url.host, url.port)<br />! http_handle.use_ssl = true if url.scheme == "https"<br />! res = http_handle.start {|http| http.request(req)}<br /> <br /> #close all the open hooks to the file on file-system<br /> @streams.each do |local_stream|Abhihttps://www.blogger.com/profile/01270973454609026559noreply@blogger.comtag:blogger.com,1999:blog-4911618396957689392.post-55991223722604448712010-11-14T13:52:48.935-08:002010-11-14T13:52:48.935-08:00Rss
Feed Suggest - Suggest
Blog - Not-Reciprocal...<a href="http://non-reciprocal.blogspot.com/2008/05/rss-feed-suggest_22.html" title="Seo - RSS FEED Atom" rel="nofollow">Rss <br />Feed Suggest</a> - <a href="http://non-reciprocal.blogspot.com/2008/05/suggest-blog.html" title="Seo - Blog Directory" rel="nofollow">Suggest <br />Blog</a> - <a href="http://non-reciprocal.blogspot.com/2007/12/non-reciprocal-submission.html" title="Seo - Web Site Search Engine" rel="nofollow">Not-Reciprocal <br />Submission</a> - <a href="http://non-reciprocal.blogspot.com/2007/12/submit-express.html" title="Seo - Easy Submission" rel="nofollow">Submission <br />Express</a> - <a href="http://non-reciprocal.blogspot.com/2007/12/auto-submit.html" title="Seo - Auto Automatic" rel="nofollow">Auto <br />Submission</a> - <a href="http://non-reciprocal.blogspot.com/2007/12/blog-ping.html" title="Seo - Blog Ping - Pinging" rel="nofollow">Blog <br />Ping</a> - <a href="http://non-reciprocal.blogspot.com/2008/02/submit-tag.html" title="Seo - Tag Tags Label Labels" rel="nofollow">Submission <br />Tag</a>Bloglarimhttps://www.blogger.com/profile/06232925571705397327noreply@blogger.comtag:blogger.com,1999:blog-4911618396957689392.post-61338618581826624232010-05-02T18:15:40.023-07:002010-05-02T18:15:40.023-07:00Hi Mark,
added the support for https.
Re-install ...Hi Mark,<br /><br />added the support for https.<br />Re-install and you should be good to go.<br />Let me know in case you find any issuesAmit Kumarhttps://www.blogger.com/profile/07178616519676182700noreply@blogger.comtag:blogger.com,1999:blog-4911618396957689392.post-23118754649255529922010-05-02T16:18:49.185-07:002010-05-02T16:18:49.185-07:00Hi Anonymous,
The content passed to the FileUpload...Hi Anonymous,<br />The content passed to the FileUploadIO is incorrect, you need to specify the content type of the file eg: "image/jpeg".<br />Sorry, if the wiki does not specify it clearly. I will update the description.Amit Kumarhttps://www.blogger.com/profile/07178616519676182700noreply@blogger.comtag:blogger.com,1999:blog-4911618396957689392.post-57803031769000203362010-04-30T06:37:18.766-07:002010-04-30T06:37:18.766-07:00Hi Amit, I'am Jenny.
I got some probleme with ...Hi Amit, I'am Jenny.<br />I got some probleme with multipart-posting. I store my data on DB, i got a message :<br /><br />'--!ruby/object:ActionController::UploadedStringIO content_type: multipart/form-data; boundary= original_filename: myfile original_path: myfile '<br /><br />My code:<br /><br /> myfile = File.new('/home/harks/Programation/Rails/ParkeonScriptV5/park/0000200368.parkeon')<br /> path_up = myfile.path<br /><br /> params = {"upload[name]" => "TestConsole",<br /> "upload[datafile]" => FileUploadIO.new(path_up,'multipart/form-data; boundary=')<br /> }<br /> <br /> url = 'http://localhost:3000/uploads'<br /> current_post = MultiPart::Post.new(params)<br /> query = '/new'<br /><br /> current_post.submit(url,query)<br /><br /><br />Thanks for listeningAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-4911618396957689392.post-53230825608852942222010-04-26T09:22:34.196-07:002010-04-26T09:22:34.196-07:00Hi Amit, Thank you for this blog and for the ruby...Hi Amit, Thank you for this blog and for the ruby-multipart-post gem. I'd like to get it to work with https. The following made the connection to https://mytestserver.edu/someapp/somescript with the httpclient, but of course I couldn't do a multipart:<br />client = HTTPClient.new<br />client.ssl_config.ciphers = 'ALL'<br />client.post(post_url, params)<br /><br />Any suggestions for getting an https connection with ruby-multipart-post? Thanks.Mark Bykerk Kauffmanhttps://www.blogger.com/profile/04515529377311657827noreply@blogger.comtag:blogger.com,1999:blog-4911618396957689392.post-68427891523857680482010-03-13T13:50:05.973-08:002010-03-13T13:50:05.973-08:00Hey thanks Rebecca for posting the comment. I have...Hey thanks Rebecca for posting the comment. I have fixed the issue. Please update the version of gem and try again. It should work now....Amit Kumarhttps://www.blogger.com/profile/07178616519676182700noreply@blogger.comtag:blogger.com,1999:blog-4911618396957689392.post-29257941103953576882010-03-10T12:00:36.842-08:002010-03-10T12:00:36.842-08:00This looks pretty sweet!
When I tried it though...This looks pretty sweet! <br /><br />When I tried it though, I got the following error: <br /><br />/Library/Ruby/Gems/1.8/gems/ruby-multipart-post-0.1.0/lib/stream.rb:12:in `+': String can't be coerced into Fixnum (TypeError)<br /> from /Library/Ruby/Gems/1.8/gems/ruby-multipart-post-0.1.0/lib/stream.rb:12:in `size'<br /> from /Library/Ruby/Gems/1.8/gems/ruby-multipart-post-0.1.0/lib/stream.rb:11:in `each'<br /> from /Library/Ruby/Gems/1.8/gems/ruby-multipart-post-0.1.0/lib/stream.rb:11:in `size'<br /> from /Library/Ruby/Gems/1.8/gems/ruby-multipart-post-0.1.0/lib/multi_part_post.rb:38:in `submit'<br /> from post_file.rb:11<br /><br /><br /><br /><br />My script:<br /> <br />require 'rubygems'<br />require "ruby-multipart-post"<br /><br />params = {<br /> "appKey" => "myAppKey", "userToken" => "myUserToken", "folder" => "myFolder",<br /> "cpFile1" => FileUploadIO.new("/path/to/my/image.jpg", "image/jpeg")<br /> }<br /><br />url = 'http://upload.cafepress.com/image.upload.cp'<br />multipart_post = MultiPart::Post.new(params) <br />multipart_post.submit(url) <br /><br />Any idea what the problem might be?<br />Thanks!<br />RebeccaRebeccanoreply@blogger.com