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


Java OSSClient.putObject方法代码示例

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


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

示例1: doPost

import com.aliyun.oss.OSSClient; //导入方法依赖的package包/类
public static String doPost(String id, MultipartFile multipartFile) throws IOException{

        OSSClient ossClient = new OSSClient(endpoint,accessKeyId,accessKeySecret);
        long currentTime = System.currentTimeMillis();
        String filename = id + String.valueOf(currentTime)+".png";

        //创建缓存文件
        File f = null;

        f = File.createTempFile("tmp", null);
        multipartFile.transferTo(f);

        //缓存文件上传至OSS
        InputStream inputStream = new FileInputStream(f);
        ossClient.putObject("zxbangban", filename, inputStream);
        //关闭OSS实例,删除临时文件
        ossClient.shutdown();
        f.deleteOnExit();
        return filename;

    }
 
开发者ID:zxbangban,项目名称:zxbangban,代码行数:22,代码来源:AliyunOSSUtil.java

示例2: putObject

import com.aliyun.oss.OSSClient; //导入方法依赖的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

示例3: putObject

import com.aliyun.oss.OSSClient; //导入方法依赖的package包/类
public static void putObject(String bucketName, File file, String fileName)
		throws IOException {

	// 初始化OSSClient
	OSSClient client = getOSSClient();

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

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

	// 必须设置ContentLength
	// meta.setContentLength(file.length());
	meta.setContentEncoding("UTF-8");
	// 上传Object.
	String key = fileName;
	PutObjectResult result = client.putObject(bucketName, key, content,
			meta);
	content.close();
}
 
开发者ID:wkeyuan,项目名称:DWSurvey,代码行数:23,代码来源:AliyunOSS.java

示例4: test

import com.aliyun.oss.OSSClient; //导入方法依赖的package包/类
@Test
public void test() throws OSSException, ClientException, IOException {
    OSSClient client = new OSSClient("oss-cn-hangzhou.aliyuncs.com", "", "", "");
    // BucketInfo info = client.getBucketInfo("edrmry");
    boolean exists = client.doesBucketExist("edrmry");
    System.out.println(exists);
    // System.out.println(client.listBuckets().size());
    // client.createBucket("dzh1");
    PutObjectResult r = client.putObject("edrmry", "dzh1.jpg", new FileInputStream("/Users/dzh/Pictures/8.pic.jpg"));
    System.out.println(r.getETag());
    OSSObject o = client.getObject("edrmry", "dzh1");
    InputStream is = o.getObjectContent();

    FileOutputStream fos = new FileOutputStream("/Users/dzh/Pictures/8.pic.2.jpg");
    int len = 0;
    byte[] buf = new byte[32];
    while ((len = is.read(buf)) != -1) {
        fos.write(buf, 0, len);
    }
    fos.flush();
    fos.close();
}
 
开发者ID:dzh,项目名称:jframe,代码行数:23,代码来源:TestOSSService.java

示例5: putObject

import com.aliyun.oss.OSSClient; //导入方法依赖的package包/类
/**
 * 上传文件
 *
 * @param path 文件路径
 * @param file 文件对象
 */
public static void putObject(String path, File file) {
    OSSClient ossClient = newOSSClient();
    try {
        ossClient.putObject(bucketName, path, file);
    } finally {
        ossClient.shutdown();
    }
}
 
开发者ID:tech-microworld,项目名称:maven-cdn-alioss-plugin,代码行数:15,代码来源:AliyunOssUtills.java

示例6: uploadOSS

import com.aliyun.oss.OSSClient; //导入方法依赖的package包/类
public static String uploadOSS(String BucketName, String name, InputStream is) {
	// 创建OSSClient实例
	OSSClient client = new OSSClient(endpoint, accessKeyId, accessKeySecret, conf);
	// 使用访问OSS
	if (StringUtils.isEmpty(name)) {
		name = DateUtils.getDate("yyyyMMdd") + "/" + DateUtils.getDate("yyyyMMddHHmmssSSSS")
				+ new Random().nextInt(1000) + ".jpg";
	}
	// 上传
	client.putObject(BucketName, name, is);
	// 关闭client
	client.shutdown();
	return ConfigUtil.getValueByKey("oss_head_url") + name;
}
 
开发者ID:WilleamZhao,项目名称:StudyJava,代码行数:15,代码来源:OSSUtil.java


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