Jump to content

New Guy On The Block With Some Questions


Recommended Posts

Hello Everyone, Been awhile since I've visited, and once again I've delved into another wonderous endeavor. This is my first encounter with XML, so I'm looking for some pointers. First off, I will start with what I'm trying to accomplish. 1) The site I'm working on allows users to upload videos, the video upon upload is sent to an encoding server. I then need to grab the xml information from the encoding server and send it to the storage server, and then grab it from the storage server to put it into a mysql database on the site server so that the video is placed under the appropriate user. That's it in a nutshell, so my questions are basically - How to make the above happen upon the user clicking upload in one fluid motion. - How to do the API call to the encoding site, and then send that API information to the Storage server so it can take and store the information. - How to grab the API information from the storage server and parse it into a mysql database. The service we are using for encoding : www.encoding.comThe service we are using for video storage: www.vid.ly Any and all help is appreciated, even if it's in the form of material to read, I've looked at the XML tutorials on W3S, but still lacking the knowledge, it's not quite clicking. If there's any more information I need to supply please let me know! Thanks!

Link to post
Share on other sites
Encoding.com's API docs say you need to make a request to their site, and will receive an XML document with response information. The request itself also contains an XML document added as an "xml" POST variable. They even have a sample PHP script that does this. I don't like it for several (purity...) reasons... but it will work.vid.ly seems to take a similar approach (seems like both services have the same authors...). vid.ly responses contain the generated URL, so you can use that to fill your DB with.Across the board, you can use DOM (my choice; has tutorials on W3Schools, though they're for JavaScript, they're easily rewritable to PHP) or SimpleXML to generate, as well as to process, all XMLs involved. Once you're ready with a request, you can use the HTTP extension (personal favorite, but will likely not be available to you) or cURL or even streams with context options (100% guaranteed to be available, but may appear odd to you if you haven't send HTTP requests by other means prior to your encounter with them) to send your requests.
Link to post
Share on other sites

Boen, Thank you for the prompt response. Although I will admit, a bit of that still looks foreign to me. As far as the PHP script on encoding.com, I am using a different script that they have provided, http://www.encoding.com/how_can_i_use_your_php_uploader_tool <--- That is the one I'm currently using. I feel really dense right now on this, as I'm pretty sure this script provides me with the link I need to send to vid.ly, I just don't know how to send it to them, and then get the final url back to put into my database.

Link to post
Share on other sites
Fileinfo.php returns JSON object with urls. {"filename":"http:\/\/pc-upload.s3.amazonaws.com\/e716afec11b7865c5b2461242a5c891fc_111.mkv","mediainfo":"http:\/\/upload.encoding.com\/mediainfo\/e716afec11b7865c5b2461242a5c891fc.xml","error":""}
So... once the upload is done, you make an HTTP request to Fileinfo.php with the SID generated by Signer.php.(That script, to me, looks more difficult than manually dealing with the API calls, as nicely outlined in the API docs)
Link to post
Share on other sites

Boen, Yes I thought it was a bit complex as well. So basically have a javascript check for when upload is complete, and when it is finished, have that run the HTTP request to fileinfo.php with the SID, and that will return a result that I can then send to vid.ly ? Lastly, if the above is correct, is all of those able to be done fluidly so that all the end user sees is "Uploading..." and then "Upload Complete.."

Link to post
Share on other sites
Yes I thought it was a bit complex as well. So basically have a javascript check for when upload is complete, and when it is finished, have that run the HTTP request to fileinfo.php with the SID, and that will return a result that I can then send to vid.ly ?
I guess so.
Lastly, if the above is correct, is all of those able to be done fluidly so that all the end user sees is "Uploading..." and then "Upload Complete.."
Add the request for vid.ly into the event handler (the one currently responsible for the "Upload Complete" message), and move the "Upload Complete" message to appear at vid.ly's response.
Link to post
Share on other sites
  • 2 weeks later...

Back again. I've made progress from last week. I now have the encoding.com section working properly, but could use some help on my javascript/xml interaction to make the vid.ly portion happen. Basically the URL that I need to send to vid.ly in xml format is stored in the javascript variable "mediainfo" .... So my round of questions today are: A) How can I send a simple javascript ran XML info to vid.ly, with the following parameters:

<?xml version="1.0"?><query><!-- Main fields --><userid></userid><userkey></userkey><action>AddMedia</action><source><sourcefile>(This is where the encoding.com URL variable needs to be placed</sourcefile></source><notify></notify><format></format></query> 

After that is sent, I am supposed to receive a response from the vid.ly server, formatted as such:

<?xml version="1.0"?><Response><Message>All medias have been added.</Message><MessageCode>2.1</MessageCode><BatchID></BatchID><Success><MediaShortLink><SourceFile></SourceFile><ShortLink></ShortLink></MediaShortLink></Success></Response>

I then need to get an idea of how to parse the response so I can insert it into an SQL database. I'm reading and re-reading the tutorials, but it's not quite clicking , so any pointers or short snippet examples would be awesome. Thanks again guys & gals!

Link to post
Share on other sites

Instead of sending it to vid.ly, send it to another PHP file on your server. That other file will in turn pass it to vid.ly, and process the response (adding it to the database in the process).I've already told you how to do this in PHP at my first reply.

Link to post
Share on other sites

Boen, Ok just re-read our thread here. Only question I have is how do I pass the javascript variable (Which is a link to the source file) from the .js page to the .php page? Once I get it to the php page I have a rough request script wrote in PHP, and then obviously parse the response into the DB, so I'm just missing how to pass the Javascript variable to the PHP page.

Link to post
Share on other sites

Using AJAX.

Add the request for vid.ly the PHP file into the event handler (the one currently responsible for the "Upload Complete" message), and move the "Upload Complete" message to appear at vid.ly's the PHP file's response.
The code for making a request would look something like
var xmlhttp = new XMLHttpRequest();xmlhttp.open("GET", "uploader.php?source="+encodeURIComponent(sourceLocation), true);xmlhttp.onreadystatechange = function() {    if (xmlhttp.readyState === 4) {        //Code that was previously in this handler    }}

where "uploader.php" is the name of the other PHP file, "sourceLocation" is a JavaScript variable containing the URL from the encoding request, and $_GET['source'] will contain that value within PHP.(you can call both "source" and "sourceLocation" with the same name... I've named them differently to avoid confusion)

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...