本文整理汇总了Java中com.aliyun.oss.model.ObjectMetadata.setContentType方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectMetadata.setContentType方法的具体用法?Java ObjectMetadata.setContentType怎么用?Java ObjectMetadata.setContentType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.aliyun.oss.model.ObjectMetadata
的用法示例。
在下文中一共展示了ObjectMetadata.setContentType方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: 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;
}
示例3: uploadCode
import com.aliyun.oss.model.ObjectMetadata; //导入方法依赖的package包/类
public String uploadCode(LanguageEnum lang, String code) {
InputStream is = new ByteArrayInputStream(code.getBytes());
StringBuilder fileName = new StringBuilder(UUID.randomUUID().toString());
switch (lang) {
case JAVA8:
fileName.append(".java");
break;
case C:
fileName.append(".c");
break;
case CPP:
fileName.append(".cpp");
break;
default:
fileName.append(".py");
break;
}
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentType("text/plain");
String filePath = generateFilePath(fileName.toString());
try {
ossClient.putObject(BUCKET, filePath, is, metadata);
return "/"+filePath;
} catch (Exception e) {
return null;
}
}
示例4: 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;
}
示例5: storeAsJson
import com.aliyun.oss.model.ObjectMetadata; //导入方法依赖的package包/类
/****
*
* @author wayshall
* @param object
* @param contentType example: MediaType.APPLICATION_OCTET_STREAM_VALUE
* @return
*/
public ObjectOperation storeAsJson(Object object, String contentType){
String json = JsonMapper.DEFAULT_MAPPER.toJson(object);
StringReader sr = new StringReader(json);
ObjectMetadata meta = new ObjectMetadata();
meta.setContentType(contentType);
return store(new ReaderInputStream(sr), meta);
}