OSS如何上传到某个文件夹
ReOSS如何上传到某个文件夹
哦,API文档好分散,终于自己找到了,自问自答吧!
String bucketName = 'your-bucket-name';//要创建的文件夹名称,在满足Object命名规则的情况下以'/'结尾String objectName = 'folder_name/'; OSSClient client = new OSSClient(OSS_ENDPOINT, ACCESS_ID, ACCESS_KEY);ObjectMetadata objectMeta = new ObjectMetadata();/*这里的size为0,注意OSS本身没有文件夹的概念,这里创建的文件夹本质上是一个size为0的Object,dataStream仍然可以有数据 */byte[] buffer = new byte[0];ByteArrayInputStream in = new ByteArrayInputStream(buffer); objectMeta.setContentLength(0);try { client.putObject(bucketName, objectName, in, objectMeta);} finally { in.close();}
赞3
踩0