private List<AbstractInputStreamContent> getImageListAsStream( File listingDir, String graphicPath ) { File graphicDir = new File( listingDir, graphicPath ); List<AbstractInputStreamContent> images = new ArrayList<AbstractInputStreamContent>(); if ( graphicDir.exists() ) { File[] imageFiles = graphicDir.listFiles(); for ( File imageFile : imageFiles ) { images.add( new FileContent( AndroidPublisherHelper.MIME_TYPE_IMAGE, imageFile ) ); } } return images; }
private AbstractInputStreamContent getImageAsStream( File listingDir, String graphicPath ) throws MojoFailureException { File graphicDir = new File( listingDir, graphicPath ); if ( graphicDir.exists() ) { File[] files = graphicDir.listFiles(); if ( files == null || files.length == 0 ) { getLog().warn( "There are no images in " + graphicDir.getAbsolutePath() ); } else if ( files.length > 1 ) { throw new MojoFailureException( "There should be exactly 1 image in " + graphicDir.getAbsolutePath() ); } else { File graphicFile = files[0]; return new FileContent( AndroidPublisherHelper.MIME_TYPE_IMAGE, graphicFile ); } } return null; }
public void insert(final File file, final String contentType, final String path) throws IOException { LOG.info("Inserting [%s] to [%s]", file, path); try { RetryUtils.retry( (RetryUtils.Task<Void>) () -> { storage.insert(config.getBucket(), path, new FileContent(contentType, file)); return null; }, GoogleUtils::isRetryable, 1, 5 ); } catch (IOException e) { throw e; } catch (Exception e) { throw new RE(e, "Failed to upload [%s] to [%s]", file, path); } }
private void publishApk( @NonNull String packageName ) throws MojoExecutionException { try { getLog().info( "Starting upload of apk " + apkFile.getAbsolutePath() ); FileContent newApkFile = new FileContent( AndroidPublisherHelper.MIME_TYPE_APK, apkFile ); Apk apk = edits.apks().upload( packageName, editId, newApkFile ).execute(); List<Integer> versionCodes = new ArrayList<Integer>(); versionCodes.add( apk.getVersionCode() ); Track newTrack = new Track().setVersionCodes( versionCodes ); edits.tracks().update( packageName, editId, track, newTrack ).execute(); publishWhatsNew( packageName, edits, editId, apk ); edits.commit( packageName, editId ).execute(); } catch ( Exception e ) { throw new MojoExecutionException( e.getMessage(), e ); } }
HttpContent content = new FileContent(contentType, requestBodyFile); System.out.println(content.getLength());
/** * Creates an input stream content instance from the given input. */ InputStreamMediaProvider( File file, String type ) { this.content = new FileContent( type, file ); }
HttpContent content = null; if (requestBodyFile != null) { content = new FileContent(contentType, requestBodyFile);
/** * Creates an input stream content instance from the given input. */ InputStreamMediaProvider( File file ) { this.content = new FileContent( null, file ); }
private AbstractInputStreamContent getImagesContent(String item) { File file = new File(basePath + "images" + java.io.File.separator + item + ".png"); return file.exists() ? new FileContent("image/png", file) : null; } }
private List<AbstractInputStreamContent> getScreenshots(String screenSize) { List<AbstractInputStreamContent> abstractInputStreamContents = Lists.newArrayList(); for (int i = 1; i < 9; i++) { File file = new File(basePath + "images" + java.io.File.separator + screenSize + java.io.File.separator + "screenshot" + i + ".png"); if (file.exists()) { abstractInputStreamContents.add(new FileContent("image/png", file)); } } return abstractInputStreamContents; }
public File uploadFile(java.io.File file) throws IOException { File fileMetadata = new File(); fileMetadata.setTitle(file.getName()); FileContent mediaContent = new FileContent("*/*", file); Drive.Files.Insert insert = drive.files().insert(fileMetadata, mediaContent); MediaHttpUploader uploader = insert.getMediaHttpUploader(); uploader.setDirectUploadEnabled(false); uploader.setProgressListener(new FileUploadListener()); return insert.execute(); }
private File actuallyModifySpreadsheet(final File original, final java.io.File export) throws IOException { final FileContent fc = new FileContent(MIME_TYPE_XLS_SPREADSHEET, export); return driveService.files().update(original.getId(), null, fc) .setFields(getFields()) .execute(); }
private File actuallyModifySpreadsheet(final File original, final java.io.File export) throws IOException { final FileContent fc = new FileContent(MIME_TYPE_XLS_SPREADSHEET, export); return driveService.files().update(original.getId(), null, fc) .setFields(getFields()) .execute(); }
public void updateFile(SyncItem syncItem) { Drive drive = driveFactory.getDrive(this.credential); try { java.io.File localFile = syncItem.getLocalFile().get(); File remoteFile = syncItem.getRemoteFile().get(); BasicFileAttributes attr = Files.readAttributes(localFile.toPath(), BasicFileAttributes.class); remoteFile.setModifiedTime(new DateTime(attr.lastModifiedTime().toMillis())); if (isGoogleAppsDocument(remoteFile)) { return; } LOGGER.log(Level.INFO, "Updating file " + remoteFile.getId() + " (" + syncItem.getPath() + ")."); if (!options.isDryRun()) { Drive.Files.Update updateRequest = drive.files().update(remoteFile.getId(), remoteFile, new FileContent(determineMimeType(localFile), localFile)); //updateRequest.setModifiedDate(true); File updatedFile = executeWithRetry(options, () -> updateRequest.execute()); syncItem.setRemoteFile(Optional.of(updatedFile)); } } catch (IOException e) { throw new JDriveSyncException(JDriveSyncException.Reason.IOException, "Failed to update file: " + e.getMessage(), e); } }
private File createSpreadsheet(final String name, final java.io.File export, final String mime) throws IOException { final FileContent fc = new FileContent(mime, export); final File parent = getOrCreateRoboZonkyFolder(); // retrieve Google folder in which to place the spreadsheet // convert the spreadsheet to Google Spreadsheet final File f = new File(); f.setName(name); f.setParents(Collections.singletonList(parent.getId())); f.setMimeType(MIME_TYPE_GOOGLE_SPREADSHEET); LOGGER.debug("Creating a new Google spreadsheet: {}.", f); final File result = driveService.files().create(f, fc) .setFields(getFields()) .execute(); // and mark the time when the file was last updated LOGGER.debug("New Google spreadsheet created: {}.", result.getId()); return result; }
private File createSpreadsheet(final String name, final java.io.File export, final String mime) throws IOException { final FileContent fc = new FileContent(mime, export); final File parent = getOrCreateRoboZonkyFolder(); // retrieve Google folder in which to place the spreadsheet // convert the spreadsheet to Google Spreadsheet final File f = new File(); f.setName(name); f.setParents(Collections.singletonList(parent.getId())); f.setMimeType(MIME_TYPE_GOOGLE_SPREADSHEET); LOGGER.debug("Creating a new Google spreadsheet: {}.", f); final File result = driveService.files().create(f, fc) .setFields(getFields()) .execute(); // and mark the time when the file was last updated LOGGER.debug("New Google spreadsheet created: {}.", result.getId()); return result; }
protected static String uploadFile(String targetAppPath, String serverURL, String testDroidApiKey) throws IOException { final HttpHeaders headers = new HttpHeaders().setBasicAuthentication(testDroidApiKey, ""); HttpRequestFactory requestFactory = HTTP_TRANSPORT.createRequestFactory(request -> { request.setParser(new JsonObjectParser(JSON_FACTORY)); request.setHeaders(headers); }); MultipartFormDataContent multipartContent = new MultipartFormDataContent(); FileContent fileContent = new FileContent("application/octet-stream", new File(targetAppPath)); MultipartFormDataContent.Part filePart = new MultipartFormDataContent.Part("file", fileContent); multipartContent.addPart(filePart); HttpRequest request = requestFactory.buildPostRequest(new GenericUrl(serverURL+"/upload"), multipartContent); AppiumResponse appiumResponse = request.execute().parseAs(AppiumResponse.class); logger.info("File id:" + appiumResponse.uploadStatus.fileInfo.file); return appiumResponse.uploadStatus.fileInfo.file; }
public static String uploadFile(String appPath, String serverURL, String username, String password) throws IOException { HttpHeaders headers = new HttpHeaders(); if (username != null) { headers.setBasicAuthentication(username, password); } HttpRequestFactory requestFactory = new NetHttpTransport().createRequestFactory(request -> { request.setParser(new JsonObjectParser(new JacksonFactory())); request.setHeaders(headers); }); MultipartContent multipartContent = new MultipartContent(); FileContent fileContent = new FileContent("application/octet-stream", new File(appPath)); MultipartContent.Part filePart = new MultipartContent.Part(new HttpHeaders() .set("Content-Disposition", "form-data; name=\"file\"; filename=\"" + fileContent.getFile().getName() + "\""), fileContent); multipartContent.addPart(filePart); HttpRequest request = requestFactory.buildPostRequest(new GenericUrl(serverURL), multipartContent); HttpResponse response = request.execute(); LoggerFactory.getLogger(AppiumDriverWrapper.class).info("response:" + response.parseAsString()); AppiumResponse appiumResponse = request.execute().parseAs(AppiumResponse.class); LoggerFactory.getLogger(AppiumDriverWrapper.class).info("File id:" + appiumResponse.uploadStatus.fileInfo.file); return appiumResponse.uploadStatus.fileInfo.file; }
if (!StringUtils.isEmpty(parameters.getFromLocalFilePath())) { FileContent fContent = new FileContent(null, new java.io.File(parameters.getFromLocalFilePath())); putFile = drive.files().create(putFile, fContent).setFields(metadata).execute();
if (!StringUtils.isEmpty(parameters.getFromLocalFilePath())) { FileContent fContent = new FileContent(null, new java.io.File(parameters.getFromLocalFilePath())); putFile = drive.files().create(putFile, fContent).setFields(metadata).execute();