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


Java ObjectMetadata.setContentType方法代码示例

本文整理汇总了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);
}
 
开发者ID:jayqqaa12,项目名称:jbase,代码行数:18,代码来源:OSSKit.java

示例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;
}
 
开发者ID:yysoft,项目名称:yy-utils,代码行数:21,代码来源:OssUploader.java

示例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;
    }
}
 
开发者ID:Eagle-OJ,项目名称:eagle-oj-api,代码行数:28,代码来源:FileUtil.java

示例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;
}
 
开发者ID:MinsxCloud,项目名称:minsx-ccs,代码行数:16,代码来源:AliyunOSSParseUtil.java

示例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);
}
 
开发者ID:wayshall,项目名称:onetwo,代码行数:15,代码来源:OssClientWrapper.java


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