troubleshooting Question

redirecting command in python!

Avatar of ldbkutty
ldbkuttyFlag for India asked on
Python
3 Comments1 Solution2532 ViewsLast Modified:
Hi All,

We have a PHP based web application which is working fine. There was a new requirement whereby a PPT file should be converted to a JPG and  I found a solution using OpenOffice + SPYCE (Python server pages..) I don't want to go in detail which is not necessary for this question!

Basically, I have this block of HTML form with AJAX form submit:

<script language="Javascript" type="text/javascript">
function fileUpload() {
    if (document.getElementById("upload_file").value == "") {
        alert("Please select ppt file");
        return false;
    }
    var formObject = document.getElementById('frm_upload_file');
    if (formObject) {
        YAHOO.util.Connect.setForm(formObject, true);
    }
    var obj1 = YAHOO.util.Connect.asyncRequest('POST', 'http://localhost:8000/convert.spy', fUpload );
    return false;
}
</script>

<form id="frm_upload_file" name="frm_upload_file">
<input type="file" name="upload_file" value="">
<input type="button" value="Upload" onclick="fileUpload();">
</form>

and convert.spy is the Python server page as follows:

<%@import name=include %>
<%\
if request.file('upload_file')!= None:
    import uno, os
    from com.sun.star.beans import PropertyValue

    (up_path, up_file) = os.path.split(request.file('upload_file').filename)
    tempfile = open(os.getcwd()+'\\temp\\'+up_file, 'wb')
    tempfile.write(request.file('upload_file').value)
    tempfile.close()

    export_format = 'impress_jpg_Export'

    url = os.getcwd()+'\\temp\\'+up_file
    url_save = uno.systemPathToFileUrl(url+ '.jpg')

    # Load File
    properties = []
    p=PropertyValue()
    p.Name = "Hidden"
    p.Value = False
    properties.append(p)

    context = uno.getComponentContext()
    resolver = context.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", context)
    ctx = resolver.resolve("uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext")
    smgr = ctx.ServiceManager
    desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop",ctx)
    doc = desktop.loadComponentFromURL('file:///'+url, "_blank", 0, tuple(properties))

    # Save File
    outproperties = (
            PropertyValue( "FilterName" , 0, export_format , 0 ),
            PropertyValue( "Overwrite" , 0, True , 0 ),
            PropertyValue( "Hidden",0, True,0))
    try:
        doc.storeToURL(url_save, outproperties)
    except:
        print "Failed while writing:"
    doc.dispose()
    raise spyceDone
%>


The convert.spy converts the PPT document into JPG using OpenOffice. It is working fine as well!!

What I want:

When the conversion is completed, I want this file to redirect to "http://localhost/mypage.php" page! I tried using

raise redirect("http://localhost/mypage.php")

but it didn't worked! Maybe because of the AJAX form submission? Is there any other way?

Please advise!
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros