本文整理匯總了Java中com.google.api.services.drive.model.File.setMimeType方法的典型用法代碼示例。如果您正苦於以下問題:Java File.setMimeType方法的具體用法?Java File.setMimeType怎麽用?Java File.setMimeType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.api.services.drive.model.File
的用法示例。
在下文中一共展示了File.setMimeType方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createFolder
import com.google.api.services.drive.model.File; //導入方法依賴的package包/類
@Override
public String createFolder(String parentPath, String newDirName) throws Exception {
File body = new File();
body.setTitle(newDirName);
body.setMimeType(FOLDER_MIME_TYPE);
GDrivePath parentGdrivePath = new GDrivePath(parentPath);
body.setParents(
Arrays.asList(new ParentReference().setId(parentGdrivePath.getGDriveId())));
try
{
File file = getDriveService(parentGdrivePath.getAccount()).files().insert(body).execute();
logDebug("created folder "+newDirName+" in "+parentPath+". id: "+file.getId());
return new GDrivePath(parentPath, file).getFullPath();
}
catch (Exception e)
{
throw convertException(e);
}
}
示例2: simpleUpload
import com.google.api.services.drive.model.File; //導入方法依賴的package包/類
public void simpleUpload(java.io.File filePath,String name,String mime) throws IOException{
driveService = getDriveService();
File fileMetadata = new File();
fileMetadata.setName(name);
fileMetadata.setMimeType(mime);
FileContent mediaContent = new FileContent(mime, filePath);
File file = driveService.files().create(fileMetadata, mediaContent)
.setFields("id")
.execute();
System.out.println("File ID: " + file.getId());
}
示例3: creatFolder
import com.google.api.services.drive.model.File; //導入方法依賴的package包/類
public void creatFolder() throws IOException {
LOGGER.info("creating new folder");
File fileMetadata = new File();
fileMetadata.setName("cemu_savegames");
fileMetadata.setMimeType("application/vnd.google-apps.folder");
File file = service.files().create(fileMetadata).setFields("id").execute();
LOGGER.info("Folder ID: " + file.getId());
folderID = file.getId();
}
示例4: move
import com.google.api.services.drive.model.File; //導入方法依賴的package包/類
@Override
public Path move(final Path file, final Path renamed, final TransferStatus status, final Delete.Callback callback, final ConnectionCallback connectionCallback) throws BackgroundException {
try {
if(status.isExists()) {
delete.delete(Collections.singletonList(renamed), connectionCallback, callback);
}
final String fileid = new DriveFileidProvider(session).getFileid(file, new DisabledListProgressListener());
if(!StringUtils.equals(file.getName(), renamed.getName())) {
// Rename title
final File properties = new File();
properties.setName(renamed.getName());
properties.setMimeType(status.getMime());
session.getClient().files().update(fileid, properties).
setSupportsTeamDrives(PreferencesFactory.get().getBoolean("googledrive.teamdrive.enable")).execute();
}
// Retrieve the existing parents to remove
final StringBuilder previousParents = new StringBuilder();
final File reference = session.getClient().files().get(fileid)
.setFields("parents")
.setSupportsTeamDrives(PreferencesFactory.get().getBoolean("googledrive.teamdrive.enable"))
.execute();
for(String parent : reference.getParents()) {
previousParents.append(parent);
previousParents.append(',');
}
// Move the file to the new folder
session.getClient().files().update(fileid, null)
.setAddParents(new DriveFileidProvider(session).getFileid(renamed.getParent(), new DisabledListProgressListener()))
.setRemoveParents(previousParents.toString())
.setFields("id, parents")
.setSupportsTeamDrives(PreferencesFactory.get().getBoolean("googledrive.teamdrive.enable"))
.execute();
return new Path(renamed.getParent(), renamed.getName(), renamed.getType(),
new PathAttributes(renamed.attributes()).withVersionId(fileid));
}
catch(IOException e) {
throw new DriveExceptionMappingService().map("Cannot rename {0}", e, file);
}
}
示例5: getPhotosFolder
import com.google.api.services.drive.model.File; //導入方法依賴的package包/類
private File getPhotosFolder() {
try {
File folder = getFile("photos");
if (folder == null) {
File photos = new File();
photos.setTitle("photos");
photos.setAppDataContents(true);
photos.setMimeType(FOLDER_MIME);
photos.setParents(Arrays.asList(new ParentReference().setId(getAppFolder().getId())));
photos = service.files().insert(photos).execute();
return photos;
} else {
return folder;
}
} catch (Exception e) {
e.printStackTrace();
if (!BuildConfig.DEBUG) Crashlytics.logException(e);
}
return null;
}
示例6: insertFile
import com.google.api.services.drive.model.File; //導入方法依賴的package包/類
/**
* Insert new file.
*
* @param title Title of the file to insert, including the extension.
* @param description Description of the file to insert.
* @param parentId Optional parent folder's ID.
* @param mimeType MIME type of the file to insert.
* @param file The file to insert.
* @return Inserted file metadata if successful, {@code null} otherwise.
*/
private File insertFile(String title, String description, String parentId, String mimeType, java.io.File file)
throws IOException {
File body = new File();
body.setTitle(title);
body.setDescription(description);
body.setMimeType(mimeType);
if (parentId != null && parentId.length() > 0) {
body.setParents(Collections.singletonList(new ParentReference().setId(parentId)));
}
FileContent mediaContent = new FileContent(mimeType, file);
return drive.files().insert(body, mediaContent).execute();
}
示例7: uploadTestFolder
import com.google.api.services.drive.model.File; //導入方法依賴的package包/類
protected File uploadTestFolder() {
File fileMetadata = new File();
fileMetadata.setTitle("testfolder");
fileMetadata.setMimeType("application/vnd.google-apps.folder");
File result = requestBody("google-drive://drive-files/insert?inBody=content", fileMetadata);
return result;
}