Now,I have a need that post a file stream,not a local file.the process is:
client(file) ---> my server ----> third party Cloud Storage,the transfer is file stream.
I have found this article:
Ruby: How to post a file via HTTP as multipart/form-data?
require 'rest_client'
RestClient.post('http://localhost:3000/foo',
:name_of_file_param => File.new('/path/to/file'))
you can see that the name_of_file_param is a local file,not stream.
so I want to know ,if this is file stream form the client ,what should I do
You should be able to use any IO object, including a stream, as the parameter:
RestClient.post('http://localhost:3000/foo', :name_of_file_param => my_stream)
Related
I am attempting to write a Twilio script to do voice broadcasting without rails - I would like to be able to run the script straight from my terminal.
I have a very simple script, straight from the twilio-rb gem docs:
# This should be in an initializer or similar
Twilio::Config.setup \
:account_sid => account,
:auth_token => token
Twilio::Call.create :to => '+1234567890', :from => '+0987654321',
:url => xml_file
xml_file is a xml file on my local machine, but it throws this error:
Error #21205: Url is not a valid url
How can I write the above script to operate off of a local xml file? The end goal is strictly to make a phone call, play an audio message, gather a button press and do an action based on the number received. The Twiml XML file should do that for me, if I can get it to work.
EDIT:
When using the dropbox share link, I get this error within the Twilio interface:
'Twilio is unable to process the Content-Type of the provided URL. Please see the Twilio Markup XML Documentation for more information on valid Content-Types.
You must return a Content-Type for all requests. Requests without a Content-Type will appear in the Debugger as a 502 Bad Gateway error.
Having a phone number, outgoing call request or action attribute refer to a non XML or audio resource.
Having a Play verb attempt to play non-audio content, such as XML or text.
Verify that that your web server is returning a Content-Type and it is the expected value
Make sure the URL noted refers to a valid resource'
To make sure, I copied an example I know will work into my XML file:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say voice="man">Hey man! Listen to this!</Say>
<Play>http://foo.com/cowbell.mp3</Play>
<Say voice="man">What did you think of that?!</Say>
<Record action="http://foo.com/handleRecording.php" method="GET" maxLength="20" finishOnKey="*"/>
<Gather action="/process_gather.php" method="GET">
<Say>Now hit some buttons!</Say>
</Gather>
<Say voice="man">Awesome! Thanks!</Say>
<Hangup/>
</Response>
Two ideas to try:
(1) If the file is read locally and sent to the Twilio server, try:
:url => 'file:///path/file.xml'
where
host in //host/ is omitted, yielding three slashes in a row.
path is the full filesystem path to your XML file.
file.xml is the name of your XML file.
(2) If the file must be publicly readable by the Twilio server, try placing it in the cloud somewhere (such as Dropbox) and using the public URL to it there.
I'm trying to test if a uri is valid (e.g. actually has content, not testing if it is well formed here) using ruby code, and I can open a uri using open(uri). But in my case, the uri is a link to a file to be downloaded and I don't want to have to download the whole file just to verify that there is content there.
Is there another solution for this?
Try this
require 'net/http'
u = URI.parse('http://www.example.com/')
status = Net::HTTP.start(u.host, u.port).head(u.request_uri).code
# status is HTTP status code
You'll need to use rescue to catch exception in case domain resolution fails.
I am using JMeter to do performance test a web page.
I have a scenario for uploading a file and downloading a file. I need to load test uploading file and downloading file scenarios.
Can any one help me how to achieve these using JMeter.
Thanks,
Raj
There are actually no difficulties in recording upload/download traffic with any HTTP sniffing tool and then emulate recorded requests in using JMeter.
In the simplest case you will get something like the following:
Thread Group to setup number of test users and loops;
for upload: 1 HTTP POST request with Use multipart/form-data for POST = true - to sent file as part of request;
for download: 1 HTTP GET request for download + Save Responses to a file listener attached to it - to save requested file.
This will look like the following:
Thread Group
Number of Threads = X
Loop Count = Y
. . .
UPLOAD HTTP Request
Method = POST
Use multipart/form-data for POST = true
-- Send Files with Request -- section:
File Path = ${testFile}
Parameter Name = datafile
MIME Type = ...
. . .
DOWNLOAD HTTP Request
Method = GET
Save Responses to a file
Filename Prefix = downloadTest_
Variable Name = testFile
. . .
Here you can find sample script implemented for schema given above: file-upload-download.jmx.
The following posts may also appear useful:
Testing load document functionality with JMeter
Performance testing: Upload and Download Scenarios with Apache JMeter
How to Test Image Upload Functionality With JMeter
JMeter Testing Multiple Random File Uploads
Handling File Upload in JMeter
I'm getting this error:
WSDL::XMLSchema::Parser::UnknownElementError
unknown element: {}HTML
at 'new'
when I consume webservices using Ruby. Here is the code snippet:
require 'soap/wsdlDriver'
wsdl = url
driver = SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver
driver.options["protocol.http.basic_auth"] << [url, user_name, password]
the url points to a well-formed xml.
Any solutions?
Can you share the wsdl file? Maybe that would help us answering it better.
In any case, I'd suggest generating the Driver classes first using wsdl2ruby. And then loding them in your Ruby file (through require). Examples (from the man pages):
# For server side:
$ wsdl2ruby.rb --wsdl myapp.wsdl --type server
# For client side:
$ wsdl2ruby.rb --wsdl myapp.wsdl --type client
If you load the URL in a web browser, does it get redirected to a different location?
In my experience, one reason the error "unknown element: {}HTML" comes up is the WSDL parser is trying to parse the HTML portion of the HTTP redirect and failing to do so. Therefore, you should deal with the redirect yourself (either in code or manually) and give the WSDL driver the final URL.
I have a file in the website and i m trying to send this file to windows application using the Response.BinaryWrite (getContent)( Where getContent is the byte array having the file which I need to send) vis HTTP post method only. Also I m adding a Header and Content-Type as application/octet-stream in the Response.
Now while reading the (httpWebResponse) response in the stream at client side(windows application) all the things (header + content-type + file + some extra bytes) are getting added. so when I try to read the file in stream it cannot be loaded since the content has chnged
Is there any way to separate the file from rest contents present in the response object..
How sahll I save this file in directory
Use System.Net.WebClient.DownloadData or DownloadFile method instead.
What language / version are you using?
If you are using a reasonably up-to-date version of C# you can use the WebClient class, and its DownloadFile method