Loading ...
Sorry, an error occurred while loading the content.

Re: [ydn-javascript] Re: $_FILES empty when using connection manager to upload an image

Expand Messages
  • Eric Miraglia
    Nick, The documentation you are looking for is here: http://developer.yahoo.com/yui/connection/#upload Your object will have responseText, responseXML (if XML
    Message 1 of 8 , Dec 14, 2006
    • 0 Attachment
      Nick,

      The documentation you are looking for is here:

      http://developer.yahoo.com/yui/connection/#upload

      Your object will have responseText, responseXML (if XML was returned), and your argument member (if you provided one).

      Regards,
      Eric

      ______________________________________________
      Eric Miraglia
      Yahoo! Presentation Platform Engineering




      On Dec 14, 2006, at 1:03 PM, Nick Weavers wrote:

      Reading through the latest docs there is not much info on how to use the
      connection manager for file uploads. The support for this feature seems
      to have been added in version 0.11.0 and is activated by setting the 2nd
      arg to setForm() to true. There is a comment in the changes log to say
      that a check was added to ensure that a new callback object handler
      called object has been provided. There is no documentation on how to
      code this or what is passed to it. I downloaded 0.12.0 and added a
      handler caller upload to my callback.
      Now, when the post is made, the callbackis onvoked and I get the alert
      box with a message:
      "uploadImage completed with status: undefined".
      Does an object get passed to the upload handler and if so, what member
      variables does it contain for me to inspect?
      My image does not get uploaded and I am stuck as I have no indication of
      what has happened.

      <script type="text/javascript" language="javascript"><!--
      var uploadImage = {
      postForm: function(){
      var sUrl = 'mysite/store_image.php';
      var theForm = document.getElementById('uploadImageForm');
      // the second argument is true to indicate file upload.
      YAHOO.util.Connect.setForm(theForm, true);
      var request = YAHOO.util.Connect.asyncRequest('POST', sUrl,
      uploadImageCallback);
      //Abort the transaction if it isn't completed in thirty seconds.
      //setTimeout("YAHOO.util.Connect.abort(request)",30000);
      }
      }

      var uploadImageCallback = {
      success: uploadImageSuccess,
      failure: uploadImageFailure,
      upload: uploadImageResult,
      argument: ['foo','bar']
      };

      function uploadImageResult(o) {
      alert("uploadImage completed with status: " + o.status);
      }
      function uploadImageFailure(o) {
      alert("uploadImage failed with status: " + o.status);
      }

      function uploadImageSuccess(o) {
      var msgDiv = document.getElementById('msgDiv');
      if(o.responseText !== undefined){
      msgDiv.innerHTML = "Transaction id: " + o.tId;
      msgDiv.innerHTML += "<br>HTTP status: " + o.status;
      msgDiv.innerHTML += "<br>Status code message: " + o.statusText;
      msgDiv.innerHTML += "<ul>HTTP headers: <li>" + o.getAllResponseHeaders
      + "</li></ul>";
      msgDiv.innerHTML += "PHP response: " + o.responseText;
      msgDiv.innerHTML += "Argument object: " + o.argument;
      }
      }
      //-->
      </script>

      TIA,
      Nick Weavers


    • Thomas S. Sha
      ... Sorry I didn t highlight the docs more succinctly in my previous reply. Have a look at the following topics:
      Message 2 of 8 , Dec 14, 2006
      • 0 Attachment
        --- In ydn-javascript@yahoogroups.com, "Nick Weavers"
        <nickweavers@...> wrote:
        >
        > Reading through the latest docs there is not much info on how to use the
        > connection manager for file uploads. The support for this feature seems
        > to have been added in version 0.11.0 and is activated by setting the 2nd
        > arg to setForm() to true. There is a comment in the changes log to say
        > that a check was added to ensure that a new callback object handler
        > called object has been provided. There is no documentation on how to
        > code this or what is passed to it. I downloaded 0.12.0 and added a
        > handler caller upload to my callback.
        > Now, when the post is made, the callbackis onvoked and I get the alert
        > box with a message:
        > "uploadImage completed with status: undefined".
        > Does an object get passed to the upload handler and if so, what member
        > variables does it contain for me to inspect?
        > My image does not get uploaded and I am stuck as I have no indication of
        > what has happened.
        Sorry I didn't highlight the docs more succinctly in my previous
        reply. Have a look at the following topics:
        http://developer.yahoo.com/yui/connection/#upload and
        http://developer.yahoo.com/yui/connection/#form

        File upload relies on the "upload" field in the callback object. The
        response object has a moderately different signature than a non-file
        upload transaction: tId, responseXML or responseText, and argument.
        Fields such as status and headers are not available due to the
        mechanism used to facilitate file upload(e.g., iframe).

        If you are still encountering problems after having a look at the
        tutorial, I can provide a functional example based on the code you
        provided. Please let me know.

        Regards,
        Thomas
      • Nick Weavers
        Hi Thomas, I think just having an example of the upload case would have helped me grasp things a little quicker as I am not well versed in javascript. 1 /* 2
        Message 3 of 8 , Dec 14, 2006
        • 0 Attachment
          Hi Thomas,

          I think just having an example of the upload case would have helped me
          grasp things a little quicker as I am not well versed in javascript.

          1 /*
          2 * This is an example callback object with an upload
          3 * member defined inline. The argument
          4 * property demonstrates how to pass multiple values
          5 * to the callback as an array.
          6 */
          7 var callback =
          8 {
          9 upload: uploadResponse, {/*upload handler code*/},
          11 argument: [argument1, argument2, argument3]
          12 }

          Once I realized that bit was missing I added the following and could
          see that I had errors in my PHP that were causing problems at the
          server side. After fixing these it all works nicely now. Thank for
          your help.

          function uploadResponse(o) {
          var msgDiv = document.getElementById('msgDiv');
          if(o.responseText !== undefined){
          msgDiv.innerHTML = "Transaction id: " + o.tId;
          msgDiv.innerHTML += "PHP response: " + o.responseText;
          msgDiv.innerHTML += "Argument object: " + o.argument;
          }


          Kind regards,
          Nick.
        • Nick Weavers
          I hope folks won t mind me taking a bit of a liberty here... but my next problem related to this post in that it follows on from the ajax image upload I now
          Message 4 of 8 , Dec 14, 2006
          • 0 Attachment
            I hope folks won't mind me taking a bit of a liberty here... but my
            next problem related to this post in that it follows on from the ajax
            image upload I now have working.

            When I upload the image it goes into a file that may overwrite one
            that already exists and is also in the browser cache. When the
            YAHOO.util.Connect.asyncRequest completes and the upload callback is
            triggered, it calls the following function to reload the image:

            function reloadImage(user) {
            var now = new Date();
            var imageObj = document.getElementById('uploaded_image');
            // Adding the current time to the URO should cause a cache update
            imageObj.src = 'mysite/images/' + user + '.jpg?' + now.getTime();

            var msgDiv = document.getElementById('msgDiv');
            msgDiv.innerHTML += "<br>imageObj.src: " + imageObj.src;
            //setTimeout('reloadImage()',10000);
            }

            The value of imageObj.src is written to div for checking and I can
            see that it is correct and yet the image does not reload. Can anyone
            tell me what I am missing?

            TIA,
            Nick
          Your message has been successfully submitted and would be delivered to recipients shortly.