Question

How to set permission of all files in a bucket as public on every upload.

Posted November 7, 2017 12.2k views
UbuntuSecurityJavaUbuntu 16.04StorageObject Storage

I am accessing DigitalOcean Spaces with the help of AWS SDK. I am able to connect and upload file to the Spaces bucket. I’m uploading a directory with recursive directories and files using ‘TransferManager.uploadDirectory()’ method. Is there a way to set permission as public as a part of uploading instead of iterating and setting individual object permission in another API call.
But I want to set permission of all files which I’m uploading as 'public’. By default it is 'private’.

I tried using AWS bucket policy .. but it is not supporting in DO Spaces.
Also everytime I upload files to that particular bucket, I want all those files to be public.

Kindly help me with this. I’m searching for a generic solution. I’m not getting any way around.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
8 answers

i’m using https://github.com/minio/minio-go, here is what i did.

    endpoint := "sgp1.digitaloceanspaces.com"
    accessKeyID := "access-key"
    secretAccessKey := "secret-access-key"
    useSSL := true

    // Initialize minio client object.
    minioClient, err := minio.New(endpoint, accessKeyID, secretAccessKey, useSSL)
    if err != nil {
        log.Fatalln(err)
    }

    // Upload the file
    bucketName := "indonesia"
    newImageName := uuid.NewV4()
    objectName := "indonesia.jpg"
        fileObject := bytes.NewReader(body)
    contentLength := r.ContentLength
    contentType := r.Header.Get("Content-type")
    cacheControl := "max-age=31536000"
       // make it public
    userMetaData := map[string]string{"x-amz-acl": "public-read"}

    n, err := minioClient.PutObject(bucketName, objectName, fileObject, contentLength, minio.PutObjectOptions{ContentType: contentType, CacheControl: cacheControl, UserMetadata: userMetaData})
    if err != nil {
        log.Fatalln(err)
    }
  • Thanks! This worked perfectly

  • Building upon the above solution I was also able to upload public files (recursively) using the Minio windows executable (mc.exe) from the command-line. So in case anyone else comes here looking for it:

    mc cp --attr x-amz-acl=public-read --recursive "<complete_path>\<folder_name>" <storage_alias>/<bucket_name>
    
    • You made my day! Was about to give up. I am working on uploading files to spaces using golang and minio. These files must be public available. The trick is to add the meta data to the PutObjectOptions:

          opts := minio.PutObjectOptions{}
          opts.UserMetadata = make(map[string] string)
          opts.UserMetadata["x-amz-acl"] = "public-read"
      
      

You have to specify ACL as public-read in the request headers:

‘x-amz-acl’: 'public-read’

You can take a look at my Github repo to get a easy solution:

https://github.com/ilovelili/digital-ocean-client

I am with same problem here. anyone on dg could help on this?

Same problem here. Digital ocean any update about this?

Same problem here. Using golang with Minio, but cannot set to public-read for file uploaded.
Any update?

I have the same proplem, ,,,,,,
Did you know how to make all the bucket public

Submit an Answer