@@ -372,4 +372,63 @@ public void run() {
372372 }
373373 }
374374
375- }
375+ @ Test
376+ public void testAcl () {
377+ String key = "test-upload-file-with-acl" ;
378+
379+ // Upload file without acl setting, returned acl will be DEFAULT.
380+ try {
381+ File file = createSampleFile (key , 1024 * 500 );
382+ UploadFileRequest uploadFileRequest = new UploadFileRequest (bucketName , key , file .getAbsolutePath (), (1024 * 100 ), 10 );
383+
384+ UploadFileResult uploadRes = ossClient .uploadFile (uploadFileRequest );
385+ Assert .assertEquals (uploadRes .getMultipartUploadResult ().getBucketName (), bucketName );
386+ Assert .assertEquals (uploadRes .getMultipartUploadResult ().getKey (), key );
387+
388+ ObjectAcl acl = ossClient .getObjectAcl (bucketName , key );
389+ Assert .assertEquals (acl .getPermission (), ObjectPermission .Default );
390+ } catch (Throwable e ) {
391+ e .printStackTrace ();
392+ Assert .fail (e .getMessage ());
393+ }
394+
395+ // Upload With PRIVATE acl setting, returned acl will be PRIVATE.
396+ try {
397+ File file = createSampleFile (key , 1024 * 500 );
398+ UploadFileRequest uploadFileRequest = new UploadFileRequest (bucketName , key , file .getAbsolutePath (), (1024 * 100 ), 10 );
399+ ObjectMetadata metadata = new ObjectMetadata ();
400+ metadata .setObjectAcl (CannedAccessControlList .Private );
401+ uploadFileRequest .setObjectMetadata (metadata );
402+
403+ UploadFileResult uploadRes = ossClient .uploadFile (uploadFileRequest );
404+ Assert .assertEquals (uploadRes .getMultipartUploadResult ().getBucketName (), bucketName );
405+ Assert .assertEquals (uploadRes .getMultipartUploadResult ().getKey (), key );
406+
407+ ObjectAcl acl = ossClient .getObjectAcl (bucketName , key );
408+ Assert .assertEquals (acl .getPermission (), ObjectPermission .Private );
409+ } catch (Throwable e ) {
410+ e .printStackTrace ();
411+ Assert .fail (e .getMessage ());
412+ }
413+
414+ // Test set acl null.
415+ try {
416+ File file = createSampleFile (key , 1024 * 500 );
417+ UploadFileRequest uploadFileRequest = new UploadFileRequest (bucketName , key , file .getAbsolutePath (), (1024 * 100 ), 10 );
418+ ObjectMetadata metadata = new ObjectMetadata ();
419+ metadata .setObjectAcl (null );
420+ uploadFileRequest .setObjectMetadata (metadata );
421+
422+ UploadFileResult uploadRes = ossClient .uploadFile (uploadFileRequest );
423+ Assert .assertEquals (uploadRes .getMultipartUploadResult ().getBucketName (), bucketName );
424+ Assert .assertEquals (uploadRes .getMultipartUploadResult ().getKey (), key );
425+
426+ ObjectAcl acl = ossClient .getObjectAcl (bucketName , key );
427+ Assert .assertEquals (acl .getPermission (), ObjectPermission .Default );
428+ } catch (Throwable e ) {
429+ e .printStackTrace ();
430+ Assert .fail (e .getMessage ());
431+ }
432+ }
433+
434+ }
0 commit comments