Hi, I am working on a mobile app that sends a post with a file (a picture) "embedded" in the body of the request. It is not inside a parameter, it is inside of the body. A simplified example of a curl statement to simulate what the request does could be this: curl -X POST my_path --data-binary my_file When the request gets to the controller the contents of the file can be retrieved like this: str = self.request.body.read I can run my tests running a server and outside of rspec and directing curl requests to localhost but that slows down the tests considerably. I need to reproduce what the curl statement does from within my tests and using only the server that rspec starts but I don''t know how. Nothing that I have tried has worked and I am kind of running out of time. My latest idea (not fully explored yet) is to work with the request object itself before running the POST statement but I have not found a way to load the body with the binary contents of a file yet and I am not sure this will actually even work. Any help would be greatly appreciated. Thank you -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
pepe wrote in post #1019809:> Hi, > > I am working on a mobile app that sends a post with a file (a picture) > "embedded" in the body of the request. I >What does that mean? ALL post requests contain the data in the body of the request.> it is not inside a parameter, > it is inside of the body. >What does that mean? Are you saying that the html element for the file upload doesn''t have a name attribute? Well, then give it one.> A simplified example of a curl statement to > simulate what the request does could be this: > > curl -X POST my_path --data-binary my_file > > When the request gets to the controller the contents of the file can > be retrieved like this: > > str = self.request.body.read >I think that would be a raw dump of what''s in the body of the request, which is different than what''s in the file.> I can run my tests running a server and outside of rspec and directing > curl requests to localhostHuh? What are you trying to test specifically? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> What does that mean? Are you saying that the html element for the file > upload doesn''t have a name attribute? Well, then give it one.There is no HTML element for the file upload The request is built by a cell phone application, not a browser, it has parameter values (e.g.: the file name) but the file contents don''t have a name associated to it. I don''t control what the phone is sending so I can''t just give it a name.> > I can run my tests running a server and outside of rspec and directing > > curl requests to localhost > > Huh? What are you trying to test specifically?What I am trying to test is the upload of the file itself from within rspec, without the use of curl. Currently I need to start a rails server as localhost and use curl to send the request to it, instead of using rspec''s started server. I am yet to find a way to ''load'' the file in the request that I want to send to rspec''s server the same way the cell phone does. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Sep 2, 2:46 pm, pepe <P...-1PhG29ZdMB/g+20BJ0uB2w@public.gmane.org> wrote:> Hi, > > I am working on a mobile app that sends a post with a file (a picture) > "embedded" in the body of the request. It is not inside a parameter, > it is inside of the body. A simplified example of a curl statement to > simulate what the request does could be this: > > curl -X POST my_path --data-binary my_file > > When the request gets to the controller the contents of the file can > be retrieved like this: > > str = self.request.body.read >Looking at the code in action pack, looks like you''ll have to setup the contents of request.env[''rack.input''] (not entirely sure what with) Fred> I can run my tests running a server and outside of rspec and directing > curl requests to localhost but that slows down the tests considerably. > I need to reproduce what the curl statement does from within my tests > and using only the server that rspec starts but I don''t know how. > Nothing that I have tried has worked and I am kind of running out of > time. My latest idea (not fully explored yet) is to work with the > request object itself before running the POST statement but I have not > found a way to load the body with the binary contents of a file yet > and I am not sure this will actually even work. > > Any help would be greatly appreciated. > > Thank you-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks a lot Fred, I''ll look into that. On Sep 2, 11:38 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Sep 2, 2:46 pm, pepe <P...-1PhG29ZdMB/g+20BJ0uB2w@public.gmane.org> wrote: > > > Hi, > > > I am working on a mobile app that sends a post with a file (a picture) > > "embedded" in the body of the request. It is not inside a parameter, > > it is inside of the body. A simplified example of a curl statement to > > simulate what the request does could be this: > > > curl -X POST my_path --data-binary my_file > > > When the request gets to the controller the contents of the file can > > be retrieved like this: > > > str = self.request.body.read > > Looking at the code in action pack, looks like you''ll have to setup > the contents of > > request.env[''rack.input''] > > (not entirely sure what with) > > Fred > > > > > > > > > I can run my tests running a server and outside of rspec and directing > > curl requests to localhost but that slows down the tests considerably. > > I need to reproduce what the curl statement does from within my tests > > and using only the server that rspec starts but I don''t know how. > > Nothing that I have tried has worked and I am kind of running out of > > time. My latest idea (not fully explored yet) is to work with the > > request object itself before running the POST statement but I have not > > found a way to load the body with the binary contents of a file yet > > and I am not sure this will actually even work. > > > Any help would be greatly appreciated. > > > Thank you-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.