本文整理汇总了Java中com.google.api.client.googleapis.media.MediaHttpUploader.setDirectUploadEnabled方法的典型用法代码示例。如果您正苦于以下问题:Java MediaHttpUploader.setDirectUploadEnabled方法的具体用法?Java MediaHttpUploader.setDirectUploadEnabled怎么用?Java MediaHttpUploader.setDirectUploadEnabled使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.api.client.googleapis.media.MediaHttpUploader
的用法示例。
在下文中一共展示了MediaHttpUploader.setDirectUploadEnabled方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: uploadFile
import com.google.api.client.googleapis.media.MediaHttpUploader; //导入方法依赖的package包/类
public static com.google.api.services.drive.model.File uploadFile(
java.io.File file, Credential credential, String parent)
throws IOException {
com.google.api.services.drive.model.File fileMetadata = new com.google.api.services.drive.model.File();
fileMetadata.setParents(Arrays.asList(new ParentReference()
.setId(parent)));
fileMetadata.setTitle(file.getName());
InputStreamContent mediaContent = new InputStreamContent(
"image/png", new BufferedInputStream(new FileInputStream(
file)));
mediaContent.setLength(file.length());
Drive.Files.Insert insert = drive.files().insert(fileMetadata,
mediaContent);
MediaHttpUploader uploader = insert.getMediaHttpUploader();
uploader.setDirectUploadEnabled(true);
return insert.execute();
}
示例2: createFile
import com.google.api.client.googleapis.media.MediaHttpUploader; //导入方法依赖的package包/类
@Override
public File createFile(String sParentID, String sName, java.io.File sFile, String sMimeType, Map<String, String> sProperties) throws IOException {
File aResult = null;
if (drive != null) {
File fileMetadata = new File();
fileMetadata.setTitle(sName);
ParentReference aParentReference = new ParentReference();
aParentReference.setId(sParentID);
fileMetadata.setParents(Arrays.asList(aParentReference));
FileContent mediaContent = new FileContent(sMimeType, sFile);
Drive.Files.Insert insert = drive.files().insert(fileMetadata, mediaContent);
MediaHttpUploader uploader = insert.getMediaHttpUploader();
uploader.setDirectUploadEnabled(false);
aResult = insert.execute();
setProperties(aResult.getId(), sProperties);
}
return aResult;
}
示例3: prepareUploader
import com.google.api.client.googleapis.media.MediaHttpUploader; //导入方法依赖的package包/类
private void prepareUploader(MediaHttpUploader uploader, long length)
{
int chunkSize = MediaHttpUploader.MINIMUM_CHUNK_SIZE * CHUNK_COUNT;
int chunkCount = (int) Math.ceil(length / (double) chunkSize);
if (showProgress && chunkCount > 1)
{
uploader.setDirectUploadEnabled(false);
uploader.setChunkSize(chunkSize);
uploader.setProgressListener(new RemoteGoogleDriveProgress(this, length));
}
else
{
uploader.setDirectUploadEnabled(true);
}
}
示例4: createFile
import com.google.api.client.googleapis.media.MediaHttpUploader; //导入方法依赖的package包/类
public File createFile(String parentId, String name, String mimeType, byte[] content, IProgressMonitor monitor) throws IOException {
File fileMetadata = new File();
fileMetadata.setTitle(name);
fileMetadata.setParents(Arrays.asList(new ParentReference().setId(parentId)));
ByteArrayContent mediaContent = new ByteArrayContent(mimeType, content);
Drive.Files.Insert insert = drive.files().insert(fileMetadata, mediaContent);
MediaHttpUploader uploader = insert.getMediaHttpUploader();
uploader.setDirectUploadEnabled(true);
FileUploadProgressListener uploadProgressListener = new FileUploadProgressListener(monitor);
uploader.setProgressListener(uploadProgressListener);
uploadProgressListener.begin();
try {
fileMetadata = insert.execute();
return fileMetadata;
} finally {
uploadProgressListener.done();
}
}
示例5: doInBackground
import com.google.api.client.googleapis.media.MediaHttpUploader; //导入方法依赖的package包/类
@Override
protected Exception doInBackground(String... photos) {
try {
// Get output Directory
// Create the PDF and set some metadata
Document document = new Document(PageSize.A4, DOCUMENT_MARGIN, DOCUMENT_MARGIN, DOCUMENT_MARGIN, DOCUMENT_MARGIN);
Resources resources = mContext.getResources();
document.addTitle(mFilename);
document.addAuthor(resources.getString(R.string.app_name));
document.addSubject(resources.getString(R.string.file_subject));
// Open the file that we will write the pdf to.
java.io.File fileContent = new java.io.File(ImageUtils.getAlbumStorageDir(MainActivity.ALBUM_NAME) + mFilename);
OutputStream outputStream = new FileOutputStream(fileContent);
PdfWriter.getInstance(document, outputStream);
document.open();
// Get the document's size
Rectangle pageSize = document.getPageSize();
float pageWidth = pageSize.getWidth() - (document.leftMargin() + document.rightMargin());
float pageHeight = pageSize.getHeight();
//Loop through images and add them to the document
for (String path : photos) {
Image image = Image.getInstance(path);
image.scaleToFit(pageWidth, pageHeight);
document.add(image);
document.newPage();
}
// Cleanup
document.close();
outputStream.close();
// Upload time!
FileContent mediaContent = new FileContent("application/pdf", fileContent);
File body = new File();
if (mFolder != null)
body.setParents(Arrays.asList(new ParentReference().setId(mFolder.getId())));
body.setTitle(mFilename);
body.setDescription(resources.getString(R.string.file_subject));
body.setMimeType("application/pdf");
Drive.Files.Insert insert = mService.files().insert(body, mediaContent);
MediaHttpUploader uploader = insert.getMediaHttpUploader();
uploader.setDirectUploadEnabled(false);
uploader.setChunkSize(MediaHttpUploader.MINIMUM_CHUNK_SIZE);
uploader.setProgressListener(new FileProgressListener());
File file = insert.execute();
Log.d("C2P", "File Id: " + file.getId());
/* Database Code */
DateFormat format = new SimpleDateFormat("MM/dd/yyyy");
Date date = new Date();
//file.getFileSize().toString()
String parentFolder = mFolder != null ? mFolder.getId() : "root";
Long size = file.getFileSize();
String fileSizeString = humanReadableByteCount(size);
Upload upload = new Upload(-1, mFilename, mFolderPath, fileSizeString, parentFolder, format.format(date), mService.about().get().execute().getUser().getEmailAddress());
UploadDataAdapter mUploadDataAdapter = new UploadDataAdapter(mContext);
mUploadDataAdapter.open();
mUploadDataAdapter.addUpload(upload);
mUploadDataAdapter.close();
} catch (Exception e) {
Log.d("C2P", "ERROR", e);
return e;
}
return null;
}
示例6: performUploadWithRetry
import com.google.api.client.googleapis.media.MediaHttpUploader; //导入方法依赖的package包/类
/**
* We need our own storage retry logic because we must recreate the
* input stream for the media uploader.
*/
private void performUploadWithRetry(final Executor executor,
final Storage service, final Bucket bucket, final StorageObject object,
final FilePath include)
throws ExecutorException, IOException, InterruptedException {
Operation a = new Operation() {
public void act()
throws IOException, InterruptedException, ExecutorException {
// Create the insertion operation with the decorated object and
// an input stream of the file contents.
Storage.Objects.Insert insertion =
service.objects().insert(bucket.getName(), object,
new InputStreamContent(
object.getContentType(), include.read()));
// Make the operation non-resumable because we have seen a dramatic
// (e.g. 1000x) speedup from this.
MediaHttpUploader mediaUploader = insertion.getMediaHttpUploader();
if (mediaUploader != null) {
mediaUploader.setDirectUploadEnabled(true);
}
executor.execute(insertion);
}
};
RetryStorageOperation
.performRequestWithRetry(executor, a, module.getInsertRetryCount());
}
示例7: updateFile
import com.google.api.client.googleapis.media.MediaHttpUploader; //导入方法依赖的package包/类
public File updateFile(String fileId, String mimeType, byte[] content, String etag,
IProgressMonitor monitor) throws IOException {
boolean needsNewRevision = needsNewRevision(fileId);
File fileMetadata = new File();
ByteArrayContent mediaContent = new ByteArrayContent(mimeType, content);
Drive.Files.Update update = drive.files().update(fileId, fileMetadata,
mediaContent);
update.setNewRevision(needsNewRevision);
if (etag != null) {
HttpHeaders headers = update.getRequestHeaders();
headers.setIfMatch(etag);
update.setRequestHeaders(headers);
}
MediaHttpUploader uploader = update.getMediaHttpUploader();
uploader.setDirectUploadEnabled(true);
FileUploadProgressListener uploadProgressListener = new FileUploadProgressListener(
monitor);
uploader.setProgressListener(uploadProgressListener);
uploadProgressListener.begin();
try {
fileMetadata = update.execute();
return fileMetadata;
} finally {
uploadProgressListener.done();
}
}
示例8: createVideoInsert
import com.google.api.client.googleapis.media.MediaHttpUploader; //导入方法依赖的package包/类
private YouTube.Videos.Insert createVideoInsert(YouTube youtube, AbstractInputStreamContent mediaContent,
String title, String description) throws IOException {
// Add extra information to the video before uploading.
Video videoObjectDefiningMetadata = new Video();
/**
* Set the video to public, so it is available to everyone (what most people want). This is
* actually the default, but I wanted you to see what it looked like in case you need to set
* it to "unlisted" or "private" via API.
*/
VideoStatus status = new VideoStatus();
status.setPrivacyStatus("public");
videoObjectDefiningMetadata.setStatus(status);
// We set a majority of the metadata with the VideoSnippet object.
VideoSnippet snippet = new VideoSnippet();
snippet.setTitle(title);
snippet.setDescription(description);
// Set completed snippet to the video object.
videoObjectDefiningMetadata.setSnippet(snippet);
/**
* The upload command includes: 1. Information we want returned after file is successfully
* uploaded. 2. Metadata we want associated with the uploaded video. 3. Video file itself.
*/
YouTube.Videos.Insert videoInsert = youtube.videos()
.insert("snippet,statistics,status", videoObjectDefiningMetadata, mediaContent);
// Set the upload type and add event listener.
MediaHttpUploader uploader = videoInsert.getMediaHttpUploader();
/**
* Sets whether direct media upload is enabled or disabled. True = whole media content is
* uploaded in a single request. False (default) = resumable media upload protocol to upload
* in data chunks.
*/
uploader.setDirectUploadEnabled(false);
return videoInsert;
}
示例9: YoutubeUpload
import com.google.api.client.googleapis.media.MediaHttpUploader; //导入方法依赖的package包/类
YoutubeUpload(File file, String token, String title, String description) throws IOException {
Credential credential = Auth.authorize(token);
youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, credential).setApplicationName("ttyrec2video.youtube").build();
Video metadata = new Video();
VideoStatus status = new VideoStatus();
status.setPrivacyStatus("public");
metadata.setStatus(status);
VideoSnippet snippet = new VideoSnippet();
snippet.setTitle(title);
snippet.setDescription(description);
metadata.setSnippet(snippet);
InputStreamContent content = new InputStreamContent("video/*", file.getAbsoluteFile().toURL().openStream());
YouTube.Videos.Insert videoinsert = youtube.videos().insert("snippet,statistics,status", metadata, content);
MediaHttpUploader uploader = videoinsert.getMediaHttpUploader();
uploader.setDirectUploadEnabled(false);
Video returnedVideo = videoinsert.execute();
System.out.println("https://youtu.be/" + returnedVideo.getId());
System.exit(0);
}