dimanche 25 novembre 2018

Upload file to specific google drive account using java

I have an application hosted in heruko, a website.

I want the users to be able to put some text in the website(using input text or something), and then I want to take this text, create from it a .txt file, and then upload it to my google drive.

I have server side written in java. It looks like :

@WebServlet( name = "uploadServlet", urlPatterns = {"/uploadFile"} )

public class uploadFIleServlet extends HttpServlet {

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
    ServletOutputStream out = resp.getOutputStream();
    out.write("hello omer you won".getBytes());

    File fileMetadata = new File();
    fileMetadata.setName("omer.txt");
    java.io.File filePath = new java.io.File("omer.txt");
    FileContent mediaContent = new FileContent("image/jpeg", filePath);
    ....
    //Send file to my google drive account using my email and password.
    //Send file to my google drive account using my email and password.
    //Send file to my google drive account using my email and password.
    //Send file to my google drive account using my email and password.
    //Send file to my google drive account using my email and password.
    //Send file to my google drive account using my email and password.
    ....
    System.out.println("File ID: " + file.getId());

    out.flush();
    out.close();
}

}

When the client asks for /uploadFile url, the "doGet" function that mentioned above is executed. So far so good.

Then, I dont know what code will do what I'm looking for, because everything I found in google documentation asks the users to log in to their google drive, what I don't want to happen.

I want the users to be able to just put text in my app, so it will be sent to my google drive account as .txt file.

I dont care putting my email and password in the java code!

So, how can I do it?

Thank you!




Aucun commentaire:

Enregistrer un commentaire