cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
641
Views
2
Helpful
6
Replies

CVP - Call Studio - Check if Audio exists

Gerry O'Rourke
Spotlight
Spotlight

Hi,

I want to check if an audio file exists (without actually playing it) in a Call Studio App.

Has anyone created some custom HTTP Get Code to do something similar?

i.e. Check if File exists. If you get a If 200 or 304 you know its there.

If you get a 404 you know its not.

Why I would like it

This will then allow me to state before doing a record prompt - that the prompt already exists and you can can ask the user to confirm if they want to overwrite the existing file.

Gerry

1 Accepted Solution

Accepted Solutions

janinegraves
Spotlight
Spotlight

If you have 11.0 or higher, you can try using the  RestClient element to

make the http request for the audio file.

Then look at the element data status_code - to see if you get 200 or 404.

I just tried this and it worked perfectly!

Although, just to be sure, you may want to set the ReadTimeout or

ConnectTimeout shorter than 5000ms, and you may want to catch  . Java

Exceptions, just in case the media server doesn't return anything in time.

View solution in original post

6 Replies 6

janinegraves
Spotlight
Spotlight

If you have 11.0 or higher, you can try using the  RestClient element to

make the http request for the audio file.

Then look at the element data status_code - to see if you get 200 or 404.

I just tried this and it worked perfectly!

Although, just to be sure, you may want to set the ReadTimeout or

ConnectTimeout shorter than 5000ms, and you may want to catch  . Java

Exceptions, just in case the media server doesn't return anything in time.

Janine - brilliant idea! Thanks.

Gerry

ptindall
Cisco Employee
Cisco Employee

HTTP HEAD method is the way to test existence and optionally get the last-modified header info.

This sort of thing --

HttpURLConnection con = (HttpURLConnection) new URL("http://cvpsvr:7000/CVP/audio/holdmusic.wav").openConnection();

con.setRequestMethod("HEAD");

System.out.println(con.getResponseCode());

System.out.println(con.getHeaderField("Last-Modified"));

con.disconnect();

Paul,

I can see that your solution might be better technically as it would not download the actually audio file (or would it? - I would have to check via wireshark), but Janine's REST Client approch is "out of the box".  Do you see any issue with using the REST Client for this use case, I don't see why not?

Gerry

Gerry,

Correct, it does what you were asking but doesn't download any response body.  It also lets you get at the headers if you need that.    REST client element doesn't unfortunately include HEAD method so would do the job but would also retrieve the audio file content.   So, you're right that HEAD is technically better but less convenient.

Paul

Paul, Janine,

Thanks to you both. I wish I could answer both your answers correct. As they both are. I might get around to creating a proper version (using Pauls method) and if I do I will post here... But Janine you get a gold star for thinking outside the box and having the solution inside the box. Thanks a mil.

Gerry