当前位置: 首页>>代码示例>>Java>>正文


Java ObjectMetadata.setContentLength方法代码示例

本文整理汇总了Java中com.aliyun.oss.model.ObjectMetadata.setContentLength方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectMetadata.setContentLength方法的具体用法?Java ObjectMetadata.setContentLength怎么用?Java ObjectMetadata.setContentLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.aliyun.oss.model.ObjectMetadata的用法示例。


在下文中一共展示了ObjectMetadata.setContentLength方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: putObject

import com.aliyun.oss.model.ObjectMetadata; //导入方法依赖的package包/类
/**
 * 上传Object
 *
 * @param client
 * @param bucketName
 * @param key
 * @param filePath
 * @return
 * @throws FileNotFoundException
 */
public static PutObjectResult putObject(OSSClient client, String bucketName, String key, String filePath) throws FileNotFoundException {

	// 获取指定文件的输入流
	File file = new File(filePath);
	InputStream content = new FileInputStream(file);

	// 创建上传Object的Metadata
	ObjectMetadata meta = new ObjectMetadata();

	// 必须设置ContentLength
	meta.setContentLength(file.length());
	// 用户自定义文件名称
	meta.addUserMetadata("filename", key);

	// 上传Object.
	PutObjectResult result = client.putObject(bucketName, key, content, meta);

	return result;
}
 
开发者ID:funtl,项目名称:framework,代码行数:30,代码来源:ObjectService.java

示例2: createEmptyObject

import com.aliyun.oss.model.ObjectMetadata; //导入方法依赖的package包/类
/**
 * Create empty object with content length is 0L
 *
 * @param bucketName
 * @param objectName
 * @throws ClientException
 * @throws OSSException
 */
private void createEmptyObject(final String bucketName, final String objectName)
        throws ClientException, OSSException {

  final InputStream nullStream = new InputStream() {
    @Override
    public int read() throws IOException {
      return -1;
    }
  };

  final ObjectMetadata om = new ObjectMetadata();
  om.setContentLength(0L);

  PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, objectName, nullStream, om);
  client.putObject(putObjectRequest);
  statistics.incrementWriteOps(1);
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:26,代码来源:OSSFileSystem.java

示例3: uploadFile

import com.aliyun.oss.model.ObjectMetadata; //导入方法依赖的package包/类
public static String uploadFile(String fileName, String path, boolean img, String contentType) throws OSSException,
		ClientException, FileNotFoundException {
	if (client == null) throw new OSSException("OssKit must init before use");

	File file = new File(path);

	ObjectMetadata objectMeta = new ObjectMetadata();
	objectMeta.setContentLength(file.length());
	if (contentType != null) objectMeta.setContentType(contentType);

	InputStream input = new FileInputStream(file);

	client.putObject(buketName, fileName, input, objectMeta);

	if (img) return getImgUrl(fileName);
	else return getUrl(fileName);
}
 
开发者ID:jayqqaa12,项目名称:jbase,代码行数:18,代码来源:OSSKit.java

示例4: putObject

import com.aliyun.oss.model.ObjectMetadata; //导入方法依赖的package包/类
@Override
protected UploadResult putObject(MultipartFile file, String path,
		String originalName, String resultName) throws IOException,
		UploadException {
	
	if(ossClient==null){
		throw new UploadException("OSS Client is null.");
	}
	
	ObjectMetadata objectMeta = new ObjectMetadata();
	objectMeta.setContentType(file.getContentType());
	
	InputStream is = file.getInputStream();
	objectMeta.setContentLength(is.available());
	
	UploadResult result = new UploadResult(path, originalName, resultName);
	ossClient.putObject(bucket, result.getFullPath(), is, objectMeta);
	//PutObjectResult ossResult = 
	return result;
}
 
开发者ID:yysoft,项目名称:yy-utils,代码行数:21,代码来源:OssUploader.java

示例5: parseToObjectMetadata

import com.aliyun.oss.model.ObjectMetadata; //导入方法依赖的package包/类
/**
 * CCSObjectMetadata 到 OSS ObjectMetadata
 */
public static ObjectMetadata parseToObjectMetadata(CCSObjectMetadata ccsObjectMetadata) {
	ObjectMetadata objectMetadata = new ObjectMetadata();
	if (ccsObjectMetadata!=null) {
		objectMetadata.setUserMetadata(ccsObjectMetadata.getUserMetaData());
		objectMetadata.setLastModified(ccsObjectMetadata.getLastModified());
		objectMetadata.setContentType(ccsObjectMetadata.getContentType());
		objectMetadata.setContentMD5(ccsObjectMetadata.getContentMD5());
		objectMetadata.setContentLength(ccsObjectMetadata.getContentLength());
		objectMetadata.setContentEncoding(ccsObjectMetadata.getContentEncoding());
	}
	return objectMetadata;
}
 
开发者ID:MinsxCloud,项目名称:minsx-ccs,代码行数:16,代码来源:AliyunOSSParseUtil.java


注:本文中的com.aliyun.oss.model.ObjectMetadata.setContentLength方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。