SitePoint Sponsor

User Tag List

Results 1 to 16 of 16

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Apr 2007
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to upload a file using web services

    Can anyone show me some example code of uploading a file using a web service?

    For the moment it is a text file.

  2. #2
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    368
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    amazon s3 do this i believe

  3. #3
    SitePoint Member
    Join Date
    Apr 2007
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I guess I need to find out how to read the file contents

    Thank you for your replay, I had a look at it. They are submitting the form as following:

    <form enctype="multipart/form-data"
    action="http://8.mihd.net/?module=upload&amp;act=classic&amp;form_auth=498c38852b9345380e659d9fe4bd22c98949327"
    method="post"
    name="uploadform">

    Now I know that this works but the point is that I basically don't have a web server, just web services. So instead of submitting a form I read the data, wrap it into a soap message and issue a web service call. I can add web services at will but I want to avoid having to program on the web server (the web service communicates with an application server).

    So I guess what I need to do is to find out how to read the CONTENTS of the file into a variable so I can submit the data to the web service.

    Any takers?

    -peter

  4. #4
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    368
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi firstly that the form on my site you looked at, lol

    amazon s3 webservice is here http://www.amazon.com/S3-AWS-home-pa...&node=16427261


    i havent looked into it myself yet, as we use secure ftp to transfer files in background, i imagine the overhead for a webservice would be massive

    but i presume the binarry data could be base64 encoded (or something similar) into the SOAP responce?

  5. #5
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    368
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i dont think this belongs in javascript forum


    anyways i found thse, could be usefull, u got me interested now
    http://support.microsoft.com/kb/318425/
    http://ajaxian.com/archives/ajax-fil...s-to-amazon-s3

  6. #6
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    813
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I guess he was trying to ask whether he can use Ajax to upload file to other web service provided by a site from different domain

  7. #7
    SitePoint Member
    Join Date
    Apr 2007
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to read the contents of a file in JavaScript

    Surely I am working on an Ajax application and I communicate with my own application server thru web services. So I am in control of both sides.

    I DO think this is a real JavaScript question, since all I want to find out is how I can read the contents of a file on the client machine into a JavaScript variable?

    First let met tackle a simple text file (which is the case at hand now) and later I suppose I will want to add base64 encoding for binary files.

    I will look at the examples provided, but they seem all POST requests but what I am looking for is the client-side JavaScript code.

  8. #8
    SitePoint Member
    Join Date
    Apr 2007
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Reading a file into a variable in JavaScript

    I tried the following which is exactly what I want, but unfortunately I get access denied in both IE and Firefox:

    var myRequest = new XMLHttpRequest;
    myRequest.open("GET","file:myfile.txt",false);
    var myText = myRequest.responseText;

  9. #9
    SitePoint Zealot
    Join Date
    Mar 2007
    Posts
    192
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Peter van Dam View Post
    Surely I am working on an Ajax application and I communicate with my own application server thru web services. So I am in control of both sides.

    I DO think this is a real JavaScript question, since all I want to find out is how I can read the contents of a file on the client machine into a JavaScript variable?

    First let met tackle a simple text file (which is the case at hand now) and later I suppose I will want to add base64 encoding for binary files.

    I will look at the examples provided, but they seem all POST requests but what I am looking for is the client-side JavaScript code.
    You cant use javascript to read the contents of a file into a variable. This poses several major security risks. You would have to get the file using a form input file, and then you would have access to the value of that, which you would then need to submit using the post method to the server. I hope that helps point you in the right direction.

  10. #10
    SitePoint Member
    Join Date
    Apr 2007
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by voodoomagic View Post
    You cant use javascript to read the contents of a file into a variable. This poses several major security risks. You would have to get the file using a form input file, and then you would have access to the value of that, which you would then need to submit using the post method to the server. I hope that helps point you in the right direction.
    OK I understand that and it makes sense (although the form method has access to local files as well but that aside).

    In order to do so, is the only possibility to first submit the file to the server and then send it back to the client in order to process it in JavaScript, or can it be done directly? If so, how?

  11. #11
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    813
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you cannot get local file with "file:" protocol. It violates the rule to protect users' security

  12. #12
    SitePoint Member
    Join Date
    Apr 2007
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So back to the drawing board. Any takers?

  13. #13
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    368
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well if you going to go to the whole bother of uplaoding to the server why dont you let the server send the file as a webservice then? instead of sending it back

    php on the server side is more capable than javascript on the client

  14. #14
    SitePoint Member
    Join Date
    Apr 2007
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by mihd View Post
    well if you going to go to the whole bother of uplaoding to the server why dont you let the server send the file as a webservice then? instead of sending it back

    php on the server side is more capable than javascript on the client
    Well it seems I cannot stay away from PHP on the web server to solve the upload problem.

    I am going to look into uploading the file to a PHP program on the server that copies it to my target server directory for subsequent processing by my normal application server through a web service command.

    Thanks for the help.

  15. #15
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    368
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here found another interesting article

    http://www.webservices.org/weblog/co...tached_to_soap

  16. #16
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    813
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    php on the server side is more capable than javascript on the client
    Well, it depends what it does first


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •