Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6917133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:41:30+00:00 2026-05-27T09:41:30+00:00

what I’m trying to do is have a upload button to upload files to

  • 0

what I’m trying to do is have a upload button to upload files to our storage system. I’m using Google App Engine with Python. Also HTML and Javascript for views.

For that, we have a HTML, and a.js that asks the user if he’s sure that he wants to overwrite a file. For that overwriting question, I need to ask the Database to know if it exists,and so if the question should be asked or not…

The thing is I don’t know even where to start. I have this confirm() text shown to the user, and a GQL database, but I don’t know how to make a question. For example, I upload via a URL, but then I don’t have a response for that, and also I don’t want to pass a question (name of the file,…) to the database via URL…

Do you have any idea of what path should I follow? Am I trying something impossible or without any sense?

Thanks a lot!

I add some code:

this is the HTML form where we ask the user to upload a file:

<form id="up_file" enctype="multipart/form-data" method="post">
                <input type="hidden" name="user_id" value="{{ current_user.id }}"/>
                <input type="hidden" name="group_id" value="{{ group.id }}"/>
                <p>File: <input type="file" name="filename" id="file_name"/></p>
                <p><input type="button" value="Upload" onClick="seguro_sobreescribir(filename,{{ current_user.id }},{{ group.id }})"/></p>
            </form> 

and this is the javascript that currently tries to send information to our application in google engine when someone clicks the upload button:

function Request(function_name, opt_argv) {
  if (!opt_argv)
    opt_argv = new Array();

  // Find if the last arg is a callback function; save it
  var callback = null;
  var len = opt_argv.length;
  if (len > 0 && typeof opt_argv[len-1] == 'function') {
    callback = opt_argv[len-1];
    opt_argv.length--;
  }
  var async = (callback != null);

  // Build an Array of parameters, w/ function_name being the first parameter
  var params = new Array(function_name);
  for (var i = 0; i < opt_argv.length; i++) {
    params.push(opt_argv[i]);
  }
  var body = JSON.stringify(params);

  // Create an XMLHttpRequest 'POST' request w/ an optional callback handler
  var req = new XMLHttpRequest();

  req.open('POST', 'https://safeshareapp.appspot.com/upload', async);

  req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  req.setRequestHeader("Content-length", body.length);
  req.setRequestHeader("Connection", "close");

  if (async) {
    req.onreadystatechange = function() {
      if(req.readyState == 4 && req.status == 200) {
        var response = null;
        try {
         response = JSON.parse(req.responseText);
        } catch (e) {
         response = req.responseText;
        }
        callback(response);
      }
    }
  }

  // Make the actual request
  req.send(body);
}


// Comprobar si existe, y si existe, preguntar si se quiere sobreescribir
function seguro_sobreescribir(filename,user_id,group_id)
{   

        var resp=confirm("Seguro que quiere sobreescribir el archivo "+filename.value+" del usuario "+user_id+" del grupo "+group_id+"?");      

        if(resp)
        {           
            var result = Request('Upload',[filename,user_id,group_id]);
            alert("Hemos hecho request "+ result);
        }       

}

And this is the RequestHandler that should handle our request:

class RPCHandler(webapp.RequestHandler):
    """ Allows the functions defined in the RPCMethods class to be RPCed."""
    def __init__(self):
        webapp.RequestHandler.__init__(self)
        self.methods = RPCMethods()

    def post(self):

        args = simplejson.loads(self.request.body)
        func, args = args[0], args[1:]

        if func[0] == '_':
            self.error(403) # access denied
            return

        func = getattr(self.methods, func, None)
        if not func:
            self.error(404) # file not found
            return

        result = func(*args)
        self.response.out.write(simplejson.dumps(result))

class RPCMethods:

    def Upload(self, *args):

        status = -1
        fileitem = args[0]        
        userid = args[1]
        groupid=args[2]    

        return status

def main():
    app = webapp.WSGIApplication([('/upload', RPCHandler)], debug=True)
    util.run_wsgi_app(app)

if __name__ == '__main__':
    main()

The fact is that the return status gives us a undefined back at the javascript.
We don’t know if we are not uploading the file and if so, how to do it. That’s because we have 2 things that we don’t know how to put together:

  • The normal “input type=file, method=post, and submit input type=submit button of a HTML form

  • Our connection via RequestHandler to the google app engine etc.

Do you have any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:41:31+00:00Added an answer on May 27, 2026 at 9:41 am

    Here’s a possibility:

    Implement a servlet that can answer the question given a filename; it could return a ‘0’ or ‘1’ (or whatever you choose) as its HTTP response depending on whether the file exists. Then make an XmlHttpRequest POST to that servlet from your javascript with the filename as a POST parameter. Depending on the return of the XmlHttpRequest, show UI to the user asking to confirm.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have thousands of HTML files to process using Groovy/Java and I need to
I am using Paperclip to handle profile photo uploads in my app. They upload
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to loop through a bunch of documents I have to put
I have a bunch of posts stored in text files formatted in yaml/textile (from
I'm making a simple page using Google Maps API 3. My first. One marker
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.