You think they will publicly read the default behavior, right? :) I shared your frustration at creating a custom API for interacting with S3 with a C # solution. Here is a snippet that downloads an S3 object and sets it for public access by default:
public void Put(string bucketName, string id, byte[] bytes, string contentType, S3ACLType acl) { string uri = String.Format("https://{0}/{1}", BASE_SERVICE_URL, bucketName.ToLower()); DreamMessage msg = DreamMessage.Ok(MimeType.BINARY, bytes); msg.Headers[DreamHeaders.CONTENT_TYPE] = contentType; msg.Headers[DreamHeaders.EXPECT] = "100-continue"; msg.Headers[AWS_ACL_HEADER] = ToACLString(acl); try { Plug s3Client = Plug.New(uri).WithPreHandler(S3AuthenticationHeader); s3Client.At(id).Put(msg); } catch (Exception ex) { throw new ApplicationException(String.Format("S3 upload error: {0}", ex.Message)); } }
The ToACLString (acl) function returns a public read , BASE_SERVICE_URL s3.amazonaws.com , and the constant is AWS_ACL_HEADER x-amz-acl . The plug and DreamMessage stuff is likely to look weird to you as we use the Dream framework to optimize our HTTP messages. Essentially, we do http PUT with the specified headers and a special header signature for aws specifications (see this page in aws docs for examples on how to create an authorization header).
To modify existing ACLs with 1000 objects, you can write a script, but it may be easier to use the GUI tool to fix the immediate problem. The best I've used so far is a company called cloudberry for S3; they seem to have a free 15-day trial for at least one of their products. I just checked that it will allow you to select several objects at once and set their ACLs for sharing via the context menu. Enjoy the cloud!
Tahbaza Jun 30 2018-10-10T00: 00Z
source share