本文整理汇总了Java中com.aliyun.openservices.oss.model.ObjectMetadata类的典型用法代码示例。如果您正苦于以下问题:Java ObjectMetadata类的具体用法?Java ObjectMetadata怎么用?Java ObjectMetadata使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ObjectMetadata类属于com.aliyun.openservices.oss.model包,在下文中一共展示了ObjectMetadata类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: add
import com.aliyun.openservices.oss.model.ObjectMetadata; //导入依赖的package包/类
@Override
public String add(InputStream input, String dir, String filename, long lenght, String contentType) throws IOException {
if (input == null) {
throw new NullPointerException("input不能为空.");
}
OSSClient client = new OSSClient(endpoint, accessKeyId, secretAccessKey);
// System.err.println("endpoint:" + endpoint);
ObjectMetadata meta = new ObjectMetadata();
meta.setContentLength(lenght);
if (contentType != null) {
meta.setContentType(contentType);
}
filename = toUuidFileName(filename);
String uri;
if (dir == null || dir.length() == 0) {
uri = filename;
}
else {
uri = dir + "/" + filename;
}
System.out.println("uri:" + uri + " lenght:" + lenght);
PutObjectResult result = client.putObject(bucketName, uri, input, meta);
System.out.println(result.getETag());
return "/" + uri;
}
开发者ID:tanhaichao,项目名称:leopard,代码行数:27,代码来源:OssClientImpl.java
示例2: upload
import com.aliyun.openservices.oss.model.ObjectMetadata; //导入依赖的package包/类
@Override
public void upload(String path, File file, String contentType) {
PluginConfig pluginConfig = getPluginConfig();
if (pluginConfig != null) {
String accessId = pluginConfig.getAttribute("accessId");
String accessKey = pluginConfig.getAttribute("accessKey");
String bucketName = pluginConfig.getAttribute("bucketName");
InputStream inputStream = null;
try {
inputStream = new FileInputStream(file);
OSSClient ossClient = new OSSClient(accessId, accessKey);
ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setContentType(contentType);
objectMetadata.setContentLength(file.length());
ossClient.putObject(bucketName, StringUtils.removeStart(path, "/"), inputStream, objectMetadata);
} catch (Exception e) {
e.printStackTrace();
} finally {
IOUtils.closeQuietly(inputStream);
}
}
}
开发者ID:justinbaby,项目名称:my-paper,代码行数:23,代码来源:OssPlugin.java
示例3: save
import com.aliyun.openservices.oss.model.ObjectMetadata; //导入依赖的package包/类
@SuppressWarnings("deprecation")
@Override
public String save(GenericFile genericFile){
OSSClient client = new OSSClient(accessKeyId, accessKeySecret);
if(!client.doesBucketExist(bucketName)){
client.createBucket(bucketName);
}
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(genericFile.getLength());
if(fileNameGenerator == null){
throw new RuntimeException("no file name generator configed");
}
String path = fileNameGenerator.gen() + genericFile.getExtend();
client.putObject(bucketName, path, genericFile.getIs(), metadata);
return path;
}
开发者ID:shangtech,项目名称:shangtech-framework,代码行数:17,代码来源:AliOSSFileSaver.java
示例4: retrieveMetadata
import com.aliyun.openservices.oss.model.ObjectMetadata; //导入依赖的package包/类
@Override
@Nullable
public FileMetadata retrieveMetadata(String key) throws IOException {
checkNotNull(key);
try {
ObjectMetadata metadata = client.getObjectMetadata(bucket, key);
return new FileMetadata(key, metadata.getContentLength(), metadata.getLastModified().getTime());
} catch (OSSException e) {
try {
throw handleException(e, key);
} catch (FileNotFoundException e2) {
LOG.debug("{} does not exist", key);
return null; // degrade gracefully
}
}
}
开发者ID:quixey,项目名称:dragon-oss,代码行数:18,代码来源:CloudOSSFileSystemStore.java
示例5: upload
import com.aliyun.openservices.oss.model.ObjectMetadata; //导入依赖的package包/类
/**
* Breaks up {@code file} into multiple parts and uploads it.
*
* @param key destination key
* @param file local file
* @param md5Hash checksum
* @throws com.aliyun.openservices.ServiceException from OSSClient.
*/
void upload(String key, File file, Optional<byte[]> md5Hash) throws IOException {
checkNotNull(key);
checkNotNull(file);
checkNotNull(md5Hash);
// initiate upload
ObjectMetadata metadata = metadata(file, md5Hash);
String uploadId = initiateMultiPartUpload(key, metadata);
// count number of parts
int parts = (int) calculateNumParts(file.length());
LOG.info("Initiating multipart upload request for key {} with {} parts", key, parts);
List<PartETag> eTags = uploadParts(key, file, uploadId, parts);
completeMultipartUpload(key, uploadId, eTags);
}
开发者ID:quixey,项目名称:dragon-oss,代码行数:25,代码来源:MultiPartUploader.java
示例6: storeEmptyFile
import com.aliyun.openservices.oss.model.ObjectMetadata; //导入依赖的package包/类
@Override
public void storeEmptyFile(String key) throws IOException {
checkNotNull(key);
try (InputStream input = new ByteArrayInputStream(new byte[0])) {
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentType("binary/octet-stream");
metadata.setContentLength(0);
client.putObject(bucket, key, input, metadata);
} catch (ServiceException e) {
throw handleException(e, key);
}
}
开发者ID:quixey,项目名称:dragon-oss,代码行数:14,代码来源:CloudOSSFileSystemStore.java
示例7: doSimpleUpload
import com.aliyun.openservices.oss.model.ObjectMetadata; //导入依赖的package包/类
private void doSimpleUpload(String key, File file, Optional<byte[]> md5Hash) throws IOException {
try (BufferedInputStream input = new BufferedInputStream(new FileInputStream(file))) {
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(file.length());
metadata.setLastModified(new Date(file.lastModified()));
// add MD5, if provided
if (md5Hash.isPresent()) {
String contentMd5 = Base64.encodeBase64String(md5Hash.get());
metadata.setHeader("Content-MD5", contentMd5.trim());
}
client.putObject(bucket, key, input, metadata);
} catch (ServiceException e) {
throw handleException(e, key);
}
}
开发者ID:quixey,项目名称:dragon-oss,代码行数:16,代码来源:CloudOSSFileSystemStore.java
示例8: upload
import com.aliyun.openservices.oss.model.ObjectMetadata; //导入依赖的package包/类
@Override
public String upload(InputStream is, String filename, String contentType, long length) throws IOException {
ObjectMetadata meta = new ObjectMetadata();
meta.setContentLength(length);
meta.setContentType(contentType);
meta.setCacheControl("max-age=" + 3600 * 1000 * 48);
meta.setLastModified(new Date());
client.putObject(name, "images/" + filename, is, meta);
return filename;
}
开发者ID:chocotan,项目名称:lolibox,代码行数:11,代码来源:AliStorageService.java
示例9: initiateMultiPartUpload
import com.aliyun.openservices.oss.model.ObjectMetadata; //导入依赖的package包/类
private String initiateMultiPartUpload(String key, ObjectMetadata metadata) {
InitiateMultipartUploadRequest request = new InitiateMultipartUploadRequest(bucket, key);
request.setObjectMetadata(metadata);
InitiateMultipartUploadResult result = client.initiateMultipartUpload(request);
return result.getUploadId();
}
开发者ID:quixey,项目名称:dragon-oss,代码行数:7,代码来源:MultiPartUploader.java
注:本文中的com.aliyun.openservices.oss.model.ObjectMetadata类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论