本文整理汇总了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;
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}