upload video to Heywatch in ASP.net
|
|
Hi all, I am currently trying to upload a video to HeyWatch, and I find it somehow quite difficult. Here what I do : // Read file data FileStream fs = new FileStream(MyFullPathFileName, FileMode.Open, FileAccess.Read); byte[] data = new byte[fs.Length]; fs.Read(data, 0, data.Length); fs.Close(); // Generate post objects Dictionary<string> postParameters = new Dictionary<string>(); postParameters.Add(“key”, ConstHeyWatch.Key); postParameters.Add(“data”, data); //create credentials credentials = new NetworkCredential(ConstHeyWatch.Username,ConstHeyWatch.Password); //perform the upload string postURL = ConstHeyWatch.UploadUrl; string userAgent = ””; HttpWebResponse webResponse = WebHelpers.MultipartFormDataPost(postURL, userAgent, postParameters,credentials); I am using ConstHeyWatch.UploadUrl as “http://heywatch.com/upload.xml” There is no error message, and the webResponse is empty. When I have a llok in my dashboard ,this one remains hopelessly empty too. Am I doing something wrong somewhere (data posted,name of data posted, information missing…) ? |
|
|
Do you have an header response to see the status code? |
|
|
Thanks Bruno. My upload works, though I do not know why really.. I am now on my way to create a job. I must say that I have real pain at making your API working. Might be because I am an underskilled programmer, but the documentation that goes with it is not very helpful either. It lacks of examples.. I willl let you know if I succedd and post my code here so that it might help other dummy programmers as I am.. |
|
|
Ok I am here struggling with downloading now: I am doing something like this. Nothing really fancy, but I simply do not understand the logic of your API. I don’t understand what is a download for you. The url given after creating the download is the same as the one provided before. Then when I am trying to download my movie fromn this url. You should think of other programmers who have nothing to do with php. Instead of having some very precise example for this technology some common piece of advices about what you get and receive and what it does stand for would be far more better ( or least would be a good complement to your php stuff) My code :ServiceVideo sv = new ServiceVideo(Store.RepositoryVideo); Download d = new Download(); d.url = "http://heywatch.com/encoded_video/1559424.bin"; // this take the piece of xml from your response and transform // it in a download object ( so there chould be the correct url) d = sv.SaveDownload(d); d.ping_url_after_transfer = "http://MyWebsite/WebServices/HeyWatch/WS_HeyWatch.asmx/EncodeError?VideoId=" + d.id; d.ping_url_if_error = "http://MyWebsite/WebServices/HeyWatch/WS_HeyWatch.asmx/EncodeError?VideoId=" + d.id; d.FileName = @"C:\temp\monfilm.flv"; // I telle him where to save my movie sv.DownloadVideo(d);Header of my web response when reaching this url :
{Connection: keep-alive
Content-Length: 3445
Cache-Control: no-cache
Content-Type: text/html; charset=utf-8
Date: Tue, 11 Aug 2009 14:11:42 GMT
Set-Cookie: _session_id=6456221f16ad3d3eeeb20263f42b3e22; path=/
Server: nginx/0.5.32
X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 2.0.4
}
this function DownloadVideo does this :
public void DownloadVideo(Download d)
{
ICredentials credentials;
credentials =
new NetworkCredential(ConstHeyWatch.Username, ConstHeyWatch.Password);
HTTPCall httpCall = new HTTPCall(System.Text.Encoding.UTF8);
WebRequest request = WebRequest.Create(d.url);
request.Credentials = Credentials;
WebResponse response = request.GetResponse();
}
I am giving it the correct credentials, but when looking at the response.Uri, I am still at the authentication page. Why should this fail when accessing this url?
Yours, Yoann |
|
|
The API is based on REST principles, and you just need to know how to request using HTTP to use it, nothing more. You’re trying to download an encoded video right? So, why are you using the ping urls in the download request (not used though)? You should listen to your network packets to see what is going on using wireshark. Paste the full request here. |
|
|
you did not reply my former question wich was : how to download an encoded video. I am using tools in dot net wich does not work on your system. So far I have tested many different possibility and nothing works: test 1: WebClient wc = new WebClient(); wc.Credentials = Credentials; wc.DownloadFile(postUrl, filename); WebClient and DownloadFile are part of the dot net framework , never had problem with it before. Here it downloads the form auth. test2 : WebRequest request = WebRequest.Create(url); request.Credentials = Credentials; request.Method = “GET”;
Same as with WebClient. it still do not pass the form authentication. The credentials are 100% correct, and I use them successfully with creating job for example! test 3 : For this test, I have given up hope concerning a possible direct downlaod of my encoded video therfore i tried to use the http_upload_directive I have created a webservice wich run fines. I have even set a log file in order to check that the web service was called. But , it is never called. I can see in the list of job that the correct url is given to the job. But there is something wrong after, for I do not see any hit of my webservice. nor in the log file, nor in the error log of the server… here is the url of my webservice : http://at.30sekunden.dynamiq.at:10000/MAIN-2009/WebServices/HeyWatch/WS_HeyWatch.asmx/GetVideo Please, help, I am about to crack, i think…. |
|
|
Sorry but I’m not a dot net guy, so I can’t help you much with your code. But I can see in the logs that you’re not authenticated correctly. You should use wireshark to have the complete request you send to us. It will help finding the problem. About the http_upload_directive, we get an HTTP 500 error from you, so you have a problem with your web service. Check your logs. I’ve found a method to download a file http://www.codeguru.com/columns/dotnettips/article.php/c7005 Hope it helps. |
|
|
Dear Bruno, Thanks for your reply. Here what I did so far: 1) I tried to get a list of job using my credential
This worked fine , so my credentials seems not to be so bad after all.. 2) I used the web interface to download an encoded movie. It allowed me to get the real url to reach the movie on your server : “http://94.23.63.190/videos/jXkrEAsdt7qUxxx/xmas2006.flv” So I used it in my code, and oh miracle , everythings was fine. ( I have changed jXkrEAsdt7qUxxx, I don’t think that piece of information should be public.. )
But when I go back to the link used to download :”http://heywatch.com/encoded_video/1575233.bin” here I don’t get anything except the authentication page. There is definetely something weird here. And I am not speaking specifically of dot net. Concerning the webservice. I did not find any error in the log corresponding to your 500 error. I will nervertheless invistigate this matter a bit more. Can you all the same, allow me a good though about this authentication wich does not work when reaching http://heywatch.com/encoded_video/xxxx.bin, it is quite strange to me… |
|
|
I think wireshark is your only option to get this problem solved. I’ve just tried using curl and it works. Here is the output: curl -v "http://u:<a href="mailto:p@heywatch.com">p@heywatch.com</a>/encoded_video/1580436.bin" * About to connect() to heywatch.com port 80 (#0) * Trying 91.121.11.87... connected * Connected to heywatch.com (91.121.11.87) port 80 (#0) * Server auth using Basic with user 'u' > GET /encoded_video/1580436.bin HTTP/1.1 > Authorization: Basic pass > User-Agent: curl/7.18.2 (i386-apple-darwin9.4.0) libcurl/7.18.2 OpenSSL/0.9.8h zlib/1.2.3 > Host: heywatch.com > Accept: */* > < HTTP/1.1 302 Found < Server: nginx/0.5.32 < Date: Fri, 14 Aug 2009 12:43:11 GMT < Content-Type: application/force-download; charset=utf-8 < Connection: keep-alive < X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 2.0.4 < Cache-Control: no-cache < Set-Cookie: _session_id=session; path=/ < location: <a href="http://94.23.63.190/videos/Vecg3GhDut/test.avi">http://94.23.63.190/videos/Vecg3GhDut/test.avi</a> < Content-Length: 112 |
|
|
Thanks for your advice, but Wireshark is a bit too deep for my understanding. And besides my colleagues do not want any dump of it to be given to some third party. So I cannot goes on. I will wait until beginning of next week since , we recently made a change to our dns. We were using an adress with a port and we changed it recently. It might have been the reason why I didn’t get anything when you called my web service. I cross my fingers, it will solve everything… Nice week end to you! |
|
|
Ok. I have been waiting this wole weekend and my new dns adress should work, but it is not the case. Besides, I don’t see any error in the log of my server. But nevetheless, we succeed at downlaoding using the ftp directive. So everything is fine. I will go on with my process and try your heySpread now. Wish me good luck or I might come back and visit you once again… :) Yoann PS: When I will have finished everything and tested that it works fine, I think I will post my code , so that some other user may find the path less steep… ciao |