Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- application - Shutting down connection pool.
- [error] 32#32: *177005 upstream prematurely closed connection while reading response header from upstream, client: 130.211.0.233, server: , request: "POST /openptp/b2731a6ff0d3470c9d98a67bebae2c3e HTTP/1.1", upstream: "http://172.17.0.1:8080/openptp/b2731a6ff0d3470c9d98a67bebae2c3e", host: "(my GAE url)", referrer: "https://(my GAE url)/openptp/b2731a6ff0d3470c9d98a67bebae2c3e"
- application - Creating Pool for datasource 'default'
- p.a.d.DefaultDBApi - Database [default] connected at jdbc:mysql://google/ptp?cloudSqlInstance=hcpf-ptp-test:us-central1:ptp-test-mysql&socketFactory=com.google.cloud.sql.mysql.SocketFactory&characterEncoding=UTF-8&useSSL=true
- play.api.Play - Application started (Prod)
- p.c.s.NettyServer - Listening for HTTP on /0:0:0:0:0:0:0:0:8080
- try {
- Logger.info("AdultPTPController: Starting File Upload...");
- File file = null;
- File fileFinal = null;
- String fileName = "";
- String fileContentType = "";
- String filePath = "";
- String fileID = "";
- // String folderIDToFind =
- // adultDemo.getNew_Provider_Id().toString();
- String folderIDToFind = adultDemo.getLegacy_Provider_Id().toString();
- Http.MultipartFormData<File> formData = request().body().asMultipartFormData();
- if (formData != null) {
- Http.MultipartFormData.FilePart<File> filePart = formData.getFile("fileAttach");
- if (filePart != null) {
- fileName = filePart.getFilename().trim();
- // Is there a file?
- if (!fileName.equals("") && fileName != null) {
- Logger.info("AdultPTPController: File Name = " + fileName);
- fileContentType = filePart.getContentType();
- file = filePart.getFile();
- long size = Files.size(file.toPath());
- // Now we have the file, let's make a copy so we have
- // the correct file info before we send to Google
- // Drive...
- String origPath = file.getCanonicalPath();
- String destPath = origPath.replace(file.getName(), "");
- Logger.info("AdultPTPController: origPath = " + origPath);
- Logger.info("AdultPTPController: destPath = " + destPath);
- filePath = destPath + fileName;
- Logger.info("AdultPTPController: filePath = " + filePath);
- Path FROM = Paths.get(origPath);
- Path TO = Paths.get(filePath);
- // overwrite existing file, if exists
- CopyOption[] options = new CopyOption[] { StandardCopyOption.REPLACE_EXISTING,
- StandardCopyOption.COPY_ATTRIBUTES };
- try {
- Files.copy(FROM, TO, options);
- } catch (final DirectoryNotEmptyException dnee) {
- dnee.printStackTrace();
- }
- // Set the file we are uploading...
- fileFinal = new File(filePath);
- Logger.info("AdultPTPController: File Final = " + fileFinal);
- // Delete the temporary file...
- Files.deleteIfExists(file.toPath());
- Logger.info("AdultPTPController: Deleted temporary file...");
- // Send the file to Google Drive...
- if (fileFinal != null) {
- // Upload the file and return the file ID...
- Logger.info("AdultPTPController: File is not null, sending to uploadFile...");
- fileID = GoogleDrive.uploadFile(fileFinal, folderIDToFind);
- Logger.info("AdultPTPController: File ID = " + fileID);
- if (!fileID.equals("")) {
- // Success...
- // Create a file record...
- FileUpload fileUpload = new FileUpload();
- // Create a unique ID...
- fileUpload.setFileKey(fileUpload.createFileKey());
- // Set the needed fields...
- fileUpload.setRecordID(adultDemo.getLegacy_Provider_Id().toString());
- fileUpload.setRecordKey(adultPTP.getPtpkey());
- fileUpload.setCreatedBy(user.getFullname());
- fileUpload.setCreatedByEmail(user.getEmail());
- fileUpload.setCreatedByKey(user.getUserkey());
- fileUpload.setCreatedDate(GlobalUtilities.getCurrentLocalDateTime());
- fileUpload.setDateCreatedDisplay(
- GlobalUtilities.getStringDate(fileUpload.getCreatedDate()));
- // Set the file info...
- fileUpload.setFileID(fileID);
- fileUpload.setFileName(fileName);
- fileUpload.setFilePath(filePath);
- String folderID = Configuration.root().getString("google.drive.folderid");
- fileUpload.setFolderID(folderID);
- // Set the URL...
- String urlString = Configuration.root().getString("server.hostname");
- String fullURL = urlString + "/downloadfile?ptpKey=" + adultPTP.getPtpkey() + "&fileID="
- + fileID;
- fileUpload.setFileURL(fullURL);
- fileUpload.save();
- }
- }
- }
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- fileID = GoogleDrive.uploadFile(fileFinal, folderIDToFind);
- public static String uploadFile(java.io.File file, String folderIDToFind) throws IOException {
- String fileID = "";
- String fileName = "";
- try {
- Logger.info("GoogleDrive: uploadFile: Starting File Upload...");
- // Build a new authorized API client service.
- Drive service = getDriveService();
- Logger.info("GoogleDrive: uploadFile: Completed Drive Service...");
- // Set the folder...
- String folderID = Configuration.root().getString("google.drive.folderid");
- Logger.info("GoogleDrive: uploadFile: Folder ID = " + folderID);
- String folderIDToUse = getSubfolderID(service, folderID, folderIDToFind);
- String fullFilePath = file.getAbsolutePath();
- Logger.info("GoogleDrive: uploadFile: Full File Path: " + fullFilePath);
- File fileMetadata = new File();
- // Let's see what slashes exist to get the correct file name...
- if (fullFilePath.contains("/")) {
- fileName = StringControl.rightBack(fullFilePath, "/");
- } else {
- fileName = StringControl.rightBack(fullFilePath, "\");
- }
- String fileContentType = getContentType(fileName);
- Logger.info("GoogleDrive: uploadFile: File Content Type: " + fileContentType);
- fileMetadata.setName(fileName);
- Logger.info("GoogleDrive: uploadFile: File Name = " + fileName);
- Logger.info("GoogleDrive: uploadFile: Setting the folder...");
- fileMetadata.setParents(Collections.singletonList(folderIDToUse));
- Logger.info("GoogleDrive: uploadFile: Folder set...");
- // Team Drive settings...
- fileMetadata.set("supportsTeamDrives", true);
- java.io.File filePath = new java.io.File(fullFilePath);
- FileContent mediaContent = new FileContent(fileContentType, filePath);
- File fileToUpload = service.files().create(fileMetadata, mediaContent).setSupportsTeamDrives(true)
- .setFields("id, parents").execute();
- fileID = fileToUpload.getId();
- Logger.info("GoogleDrive: uploadFile: File ID: " + fileID);
- } catch (Exception ex) {
- System.out.println(ex.toString());
- ex.printStackTrace();
- }
- Logger.info("GoogleDrive: uploadFile: Ending File Upload...");
- return fileID;
- }
- application - AdultPTPController: Starting File Upload...
- application - AdultPTPController: File Name = icon_Add_User2.png
- application - AdultPTPController: origPath = /tmp/playtemp3821505761099468678/multipartBody536561590473173911asTemporaryFile
- application - AdultPTPController: destPath = /tmp/playtemp3821505761099468678/
- application - AdultPTPController: filePath = /tmp/playtemp3821505761099468678/icon_Add_User2.png
- application - AdultPTPController: File Final = /tmp/playtemp3821505761099468678/icon_Add_User2.png
- application - AdultPTPController: Deleted temporary file...
- application - AdultPTPController: File is not null, sending to uploadFile...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement