本文整理汇总了Java中com.aliyun.oss.model.PutObjectResult类的典型用法代码示例。如果您正苦于以下问题:Java PutObjectResult类的具体用法?Java PutObjectResult怎么用?Java PutObjectResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PutObjectResult类属于com.aliyun.oss.model包,在下文中一共展示了PutObjectResult类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: putObject
import com.aliyun.oss.model.PutObjectResult; //导入依赖的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();
}
示例2: putObject
import com.aliyun.oss.model.PutObjectResult; //导入依赖的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;
}
示例3: putObject
import com.aliyun.oss.model.PutObjectResult; //导入依赖的package包/类
/**
* Enhanced to auto choose simple or multipart upload via multipart upload threshold.
*
* @param putObjectRequest
* @return
* @throws OSSException
* @throws ClientException
*/
@Override
public PutObjectResult putObject(PutObjectRequest putObjectRequest)
throws OSSException, ClientException {
if (putObjectRequest.getInputStream() != null) {
return super.putObject(putObjectRequest);
} else if (putObjectRequest.getFile() != null) {
File backupFile = putObjectRequest.getFile();
if (!isMultipartUpload(backupFile)) {
return super.putObject(putObjectRequest); ////simple upload
} else {
return this.doMultiPartUpload(putObjectRequest); //multi-part upload
}
}
return super.putObject(putObjectRequest);
}
示例4: test
import com.aliyun.oss.model.PutObjectResult; //导入依赖的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();
}
示例5: parseToCCSPutObjectResponse
import com.aliyun.oss.model.PutObjectResult; //导入依赖的package包/类
/**
* OSS PutObjectResult 到 CCSPutObjectResponse
*/
@SuppressWarnings("deprecation")
public static CCSPutObjectResponse parseToCCSPutObjectResponse(PutObjectResult result) {
CCSPutObjectResponse ccsPutObjectResponse = new CCSPutObjectResponse();
ccsPutObjectResponse.seteTag(result.getETag());
ccsPutObjectResponse.setResponseBody(result.getCallbackResponseBody());
return ccsPutObjectResponse;
}
示例6: putObject
import com.aliyun.oss.model.PutObjectResult; //导入依赖的package包/类
@Override
public CCSPutObjectResponse putObject(String bucketName, String ccsObjectPath, File sourceFile,
CCSObjectMetadata ccsObjectMetadata) {
PutObjectResult result = ossClient.putObject(bucketName, ccsObjectPath, sourceFile,
AliyunOSSParseUtil.parseToObjectMetadata(ccsObjectMetadata));
return AliyunOSSParseUtil.parseToCCSPutObjectResponse(result);
}
示例7: putBlob
import com.aliyun.oss.model.PutObjectResult; //导入依赖的package包/类
@Override
public String putBlob(String container, Blob blob) {
OSS oss = api.getOSSClient(OSSApi.DEFAULT_REGION);
String region = oss.getBucketLocation(container);
oss = api.getOSSClient(region);
PutObjectResult result = null;
try {
result = oss.putObject(container, blob.getMetadata().getProviderId(), blob.getPayload().openStream());
} catch (Exception e) {
logger.warn(e.getMessage());
}
return result.getETag();
}
示例8: put
import com.aliyun.oss.model.PutObjectResult; //导入依赖的package包/类
/**
* 上传文件
* @param filePath 上传后的文件所在OSS的目录、路径,如 "jar/file/"
* @param fileName 上传的文件名,如“xnx3.jar”;主要拿里面的后缀名。也可以直接传入文件的后缀名如“.jar”
* @param inputStream {@link InputStream}
* @return {@link PutResult} 若失败,返回null
*/
public PutResult put(String filePath,String fileName,InputStream inputStream){
String fileSuffix=com.xnx3.Lang.subString(fileName, ".", null, 3); //获得文件后缀,以便重命名
String name=Lang.uuid()+"."+fileSuffix;
String path = filePath+name;
PutObjectResult pr = getOSSClient().putObject(bucketName, path, inputStream);
return new PutResult(name, path,url+path);
}
示例9: put
import com.aliyun.oss.model.PutObjectResult; //导入依赖的package包/类
/**
* 上传文件
* @param filePath 上传后的文件所在OSS的目录、路径,如 "jar/file/"
* @param fileName 上传的文件名,如“xnx3.jar”;主要拿里面的后缀名。也可以直接传入文件的后缀名如“.jar”
* @param inputStream {@link InputStream}
* @return {@link PutResult} 若失败,返回null
*/
public static PutResult put(String filePath,String fileName,InputStream inputStream){
String fileSuffix=com.xnx3.Lang.subString(fileName, ".", null, 3); //获得文件后缀,以便重命名
String name=Lang.uuid()+"."+fileSuffix;
String path = filePath+name;
PutObjectResult pr = getOSSClient().putObject(bucketName, path, inputStream);
return new PutResult(name, path,url+path);
}
示例10: upload1
import com.aliyun.oss.model.PutObjectResult; //导入依赖的package包/类
@GetMapping("/aliyun/upload1")
public String upload1() {
PutObjectResult putObjectResult = aliyunOssClient.putObject(OssConstant.ALIYUN_OSS_BUCKET_NAME, "text.txt", new ByteArrayInputStream("Hello OSS".getBytes()));
return "success";
}
示例11: upload2
import com.aliyun.oss.model.PutObjectResult; //导入依赖的package包/类
@GetMapping("/aliyun/upload2")
public String upload2() throws FileNotFoundException {
File file = new File("d:\\zheng.png");
PutObjectResult putObjectResult = aliyunOssClient.putObject(OssConstant.ALIYUN_OSS_BUCKET_NAME, "file.png", file);
return "success";
}
示例12: doMultiPartUpload
import com.aliyun.oss.model.PutObjectResult; //导入依赖的package包/类
/**
* Do OSS multiple part upload
*
* @param putObjectRequest
* @return
*/
private PutObjectResult doMultiPartUpload(PutObjectRequest putObjectRequest) {
File backupFile = putObjectRequest.getFile();
//Claim a upload id firstly
String uploadId;
InitiateMultipartUploadRequest request = new InitiateMultipartUploadRequest(putObjectRequest.getBucketName(), putObjectRequest.getKey());
InitiateMultipartUploadResult result = this.initiateMultipartUpload(request);
uploadId = result.getUploadId();
long optimalPartSize = calculateOptimalPartSize(backupFile);
int totalParts = (int) Math.ceil((double) backupFile.length() / optimalPartSize);
//Upload multi-parts to the bucket
if (LOG.isInfoEnabled()) {
LOG.info("Begin to upload multi-parts to OSS from a {}\n", backupFile.getPath());
}
List<Future<PartETag>> futures = new ArrayList<Future<PartETag>>();
for (int i = 0; i < totalParts; i++) {
long startPos = i * optimalPartSize;
long curPartSize = (i + 1 == totalParts) ? (backupFile.length() - startPos) : optimalPartSize;
futures.add(threadPoolExecutor.submit(new PartUploadCallable(putObjectRequest.getBucketName(), putObjectRequest.getKey(),
backupFile, startPos, curPartSize, i + 1, uploadId)));
}
List<PartETag> partETags = collectPartETags(futures);
//Verify whether all parts are finished
if (partETags.size() != totalParts) {
throw new IllegalStateException("Upload multi-parts fail due to some parts are not finished yet");
} else {
LOG.info("Succeed to complete multi-parts into an object named {}", putObjectRequest.getKey());
}
// Make part numbers in ascending order
Collections.sort(partETags, new Comparator<PartETag>() {
@Override
public int compare(PartETag p1, PartETag p2) {
return p1.getPartNumber() - p2.getPartNumber();
}
});
LOG.info("Completing to upload multi-parts\n");
CompleteMultipartUploadRequest completeMultipartUploadRequest =
new CompleteMultipartUploadRequest(putObjectRequest.getBucketName(), putObjectRequest.getKey(), uploadId, partETags);
CompleteMultipartUploadResult completeResult = this.completeMultipartUpload(completeMultipartUploadRequest);
PutObjectResult putObjectResult = new PutObjectResult();
putObjectResult.setETag(completeResult.getETag());
return putObjectResult;
}
示例13: putObject
import com.aliyun.oss.model.PutObjectResult; //导入依赖的package包/类
public PutObjectResult putObject(PutObjectRequest request){
return ossClient.putObject(request);
}
示例14: storeResult
import com.aliyun.oss.model.PutObjectResult; //导入依赖的package包/类
public Optional<PutObjectResult> storeResult() {
return Optional.ofNullable(storeResult);
}