Indigo Rose Software

Professional Software Development Tools

 
+ Reply to Thread
Results 1 to 12 of 12
  1. #1
    Join Date
    Jul 2004
    Posts
    13

    File Upload through HTTP.Submit Action

    I've been trying to use the HTTP.Submit action to upload a file into a Web Server. There were some issues with the HTTP.Submit action before, and it has been resolved as per the release of latest version.

    Now my problem is, I can't still use this action to upload the file into the Web Server. Is this really possible with this action or not? I've tried using an HTTP activeX before which achieve the desired result. The activeX was also using HTTP Protocol so I am assuming that this should also be possible with HTTP.Submit.

    If it is not possible, this will be a great enhancement for the HTTP.Submit Action.

    Thanks,
    Ninj

  2. #2
    Join Date
    Jun 2000
    Location
    Indigo Rose Software
    Posts
    1,943
    Hi Ninj,

    Perhaps you could post your current action so that everyone here can have a look at it and perhaps make some suggestions?

    What size file are you uploading? How is your Web script performing the upload? Is any part of the file being uploaded to your server? Is there an error code being returned by the HTTP.Submit() action? If so what is the error? What does HTTP.GetHTTPErrorInfo() return?

    I believe that you said in the past that you have gotten this to work by increasing the timeout time to a very large number, does this still hold true?

    Truthfully I do not see why the HTTP.Submit() action would not work in this scenario since, the action is simply passing the data to the web script, which then has to perform the actual upload task. Can you get this action to work on an empty text file?
    MSI Factory The Next Generation Intelligent Setup Builder

  3. #3
    Join Date
    Jul 2004
    Posts
    13
    Below is my script:

    myValues = { filesfolder="/tu", OpCode=2, filesize=_FileSize, logfile="LogFile.txt", nameoffile="test.txt"};
    SubmitFName = HTTP.Submit("http://www.mywebserver.com/cgi-bin/uploadtest.cgi", myValues, SUBMITWEB_POST, 200, 80, nil, nil);

    Attached is a copy of the uploadtest.cgi, in order to attach it here I renamed as .txt.

    As you have said, I thought that I have made it work before. However, I just noticed that the uploaded file is an empty file with 0 bytes. Therefore, the data was not really sent to the cgi, just the filename it seems.

    Actually, I am already using the attached cgi for another application and am trying to make the upload work in TU2 as well without having to create another cgi script. Using a 3rd party HTTP activeX, the cgi script attached is able to upload a file to the server.
    Attached Files

  4. #4
    Join Date
    Jun 2000
    Location
    Indigo Rose Software
    Posts
    1,943
    Hi Ninj,

    I tried to test this on my side but I kept getting error 2516 ("An internal server error has occurred." HTTP error code 500) when trying to test your script. This is probably because I do not have something needed installed on my server or something like that, but just to make sure do you receive any errors when you test your script?

    Try inserting an Application.GetLastError() after the HTTP.Submit() action and test what the results are.
    MSI Factory The Next Generation Intelligent Setup Builder

  5. #5
    Join Date
    Jul 2003
    Posts
    712
    Hello Ninj,

    From what i can determine with yoru action, you're not actually passing the script any data to write into the file. A web script can't come onto your system and grab a file without permission. If you use that script through IE, IE has permission to access files on your system that you let it, and send them off to the script. Or at least that's how I understand it.

    But with TrueUpdate, the script can access only what values you send to it from your lua script. Thoguh i'm not positive, how I would envision a file upload working is as follows:

    1. UUencode the file in trueupdate (i'm not entirely sure how to do this)
    2. send the following values to your script:
    filename - the file, in form filename.ext
    filedata - the actual data, the uuencoded string
    3. Create a script that accepts those two values, uudecodes the string, and writes the filestream to the specified filename on the server. I haven't tried this, but in php i'd do somethign like this (please keep in mind this hasn't been tried or tested, but is where i'd start):

    Code:
    //save the below code into, say, upload.php and access it from trueupdate, method = post
    
    <?php
    //NEED POST VARIABLES:
    //filedata: uuencoded string of file contents
    //filename: string in form filename.ext
    
    $filedata = convert_uudecode($_POST['filedata']);
    
    if (!($writefilestream = fopen($_POST['filename'], 'w')))
       return;
    
    fprintf($writefilestream, "%s", $filedata);
    
    ?>
    All I did was googled uudecode and php, then writing to a file, and found those functions. Does it work? WHo knows! But this shoudl give you a place to start.

    Lemme know how this works out for you. I've never done this, so it's kinda interesting!

  6. #6
    Join Date
    Dec 2003
    Location
    Location! Location!
    Posts
    6,137
    Quote Originally Posted by Desmond
    Hello Ninj,

    From what i can determine with yoru action, you're not actually passing the script any data to write into the file. A web script can't come onto your system and grab a file without permission. If you use that script through IE, IE has permission to access files on your system that you let it, and send them off to the script. Or at least that's how I understand it.

    But with TrueUpdate, the script can access only what values you send to it from your lua script. Thoguh i'm not positive, how I would envision a file upload working is as follows:

    1. UUencode the file in trueupdate (i'm not entirely sure how to do this)
    2. send the following values to your script:
    filename - the file, in form filename.ext
    filedata - the actual data, the uuencoded string
    3. Create a script that accepts those two values, uudecodes the string, and writes the filestream to the specified filename on the server. I haven't tried this, but in php i'd do somethign like this (please keep in mind this hasn't been tried or tested, but is where i'd start):

    Code:
    //save the below code into, say, upload.php and access it from trueupdate, method = post
    
    <?php
    //NEED POST VARIABLES:
    //filedata: uuencoded string of file contents
    //filename: string in form filename.ext
    
    $filedata = convert_uudecode($_POST['filedata']);
    
    if (!($writefilestream = fopen($_POST['filename'], 'w')))
       return;
    
    fprintf($writefilestream, "%s", $filedata);
    
    ?>
    All I did was googled uudecode and php, then writing to a file, and found those functions. Does it work? WHo knows! But this shoudl give you a place to start.

    Lemme know how this works out for you. I've never done this, so it's kinda interesting!
    I would recommend also if you use that PHP code to "lock" the file. (flock)
    Intrigued

  7. #7
    Join Date
    Jul 2003
    Posts
    712
    oooh, that's a good point. to prevent possible errors cause of two attempts to write, right?

    Is the code above correct? I'm oober new to PHP, i wasn't sure.

  8. #8
    Join Date
    Dec 2003
    Location
    Location! Location!
    Posts
    6,137
    Here is an example of using the flock function from php.net (and a link to the page):

    http://us2.php.net/flock

    PHP Code:
    <?php

    $fp 
    fopen("/tmp/lock.txt""w+");

    if (
    flock($fpLOCK_EX)) { // do an exclusive lock
       
    fwrite($fp"Write something here\n");
       
    flock($fpLOCK_UN); // release the lock
    } else {
       echo 
    "Couldn't lock the file !";
    }

    fclose($fp);

    ?>
    Intrigued

  9. #9
    Corey is offline Indigo Rose Staff Alumni
    Join Date
    Aug 2002
    Posts
    9,746
    FWIW if a script is hitting a single file with simultaneous writes, it's a planning issue. PHP flock wouldn't cure that because you would still be "losing" writes, i.e. if a script's author is seeking to write two pieces of data at the same time then presumably they also wish to also read them... So in that case you would just use unique temp files in a FIFO cycle.

    Note from php.net:

    flock() will not work on NFS and many other networked file systems. Check your operating system documentation for more details.

    On some operating systems flock() is implemented at the process level. When using a multithreaded server API like ISAPI you may not be able to rely on flock() to protect files against other PHP scripts running in parallel threads of the same server instance!

    flock() is not supported on antiquated filesystems like FAT and its derivates and will therefore always return FALSE under this environments (this is especially true for Windows 98 users).

  10. #10
    Join Date
    Dec 2003
    Location
    Location! Location!
    Posts
    6,137
    I just wanted to put forth a point with regards to using fopen, as the original poster is. Whether that was the right choice... that's up for discussion and you Corey have more PHP experience than I and have found some good counter points to using fopen.

    Intrigued

  11. #11
    Corey is offline Indigo Rose Staff Alumni
    Join Date
    Aug 2002
    Posts
    9,746
    Yes I'm glad you did. This also applies to all scripting, not just PHP. In general writing twice to one file such that it would cause an error is something to plan for beforehand in all scripts/programs which write files. Common methods include using temp files or using a "flag file" to detect when another file is "ready for writing" and a corresponding file queue, etc...

  12. #12
    Join Date
    Oct 2005
    Posts
    7

    upload text file

    I started same one in nes thread.
    Last edited by mcme; 10-14-2005 at 03:07 PM. Reason: started in new thread

Similar Threads

  1. 2 BUGS...Internet Download action and File Search Action
    By Martin_SBT in forum AutoPlay Media Studio 4.0
    Replies: 3
    Last Post: 07-08-2003, 08:30 AM
  2. HOWTO: "Hide" Externally Referenced Files
    By Support in forum AutoPlay Media Studio 4.0 Examples
    Replies: 0
    Last Post: 10-23-2002, 03:19 PM
  3. INFO: Tips for Debugging Action Lists in AutoPlay Media Studio 4.0
    By Support in forum AutoPlay Media Studio 4.0 Examples
    Replies: 0
    Last Post: 10-03-2002, 08:38 AM
  4. SUF6.0.0.2 -- installer hangs.
    By jassing in forum Setup Factory 6.0
    Replies: 4
    Last Post: 12-19-2001, 11:28 PM
  5. Replies: 0
    Last Post: 08-17-2000, 02:29 PM

Posting Permissions

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