IOS AWSS3 SDK上传被拒绝AWSS3BucketCannedACLPublicReadWrite

时间:2017-06-11 20:31:32

标签: objective-c amazon-s3 awss3transfermanager

尝试使用公开读取权限将图像上传到Amazon S3。

上传已拒绝:

使用ACL 'PublicReadWrite'

stopService()

上传成功:

ACL '私人'

public class NotificationService extends Service {

private final long TIME_WAKE_UP = 6000;//60 * 60 * 1000;
private long timeStart;
private Esercizio es;

@Override
public void onCreate() {
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
    Notification mNt = mBuilder.build();
    startForeground(2, mNt);
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    timeStart = intent.getExtras().getLong("timeStart");
    es = (Esercizio) intent.getExtras().get("esercizio");

    while(System.currentTimeMillis() < timeStart + TIME_WAKE_UP);

    atWork();

    stopForeground(true);
    stopSelf();

    return START_STICKY;
}

private void atWork() {
    Intent intent = new Intent(this, TransitionArchive.class);
    Bundle bundle = new Bundle();
    bundle.putString("notificationService","");
    bundle.putString("KEY_EXCERSIZE",es.getNameEx());
    intent.putExtras(bundle);

        NotificationCompat.Builder mBuilderOffline =
                new NotificationCompat.Builder(this)
                        .setSmallIcon(R.drawable.logo_app_android)
                        .setContentTitle(es.getNameEx())
                        .setContentText("C'è un nuovo contenuto per te!")
                        .setAutoCancel(true)
                        .setPriority(Notification.PRIORITY_MAX)
                        .setVisibility(NotificationCompat.VISIBILITY_PUBLIC);

        PendingIntent pendingIntent = PendingIntent.getActivity(this,
                1,
                intent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        mBuilderOffline.setContentIntent(pendingIntent);

        //PendingIntent call the receive class

        Notification note = mBuilderOffline.build();
        note.defaults |= Notification.DEFAULT_SOUND;
        note.defaults |= Notification.DEFAULT_VIBRATE;

        NotificationManager mNotificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(1, note);
}

public static void startNotificationService(Context mContext, Esercizio es) {
    Intent mIntent = new Intent(mContext, NotificationService.class);
    mIntent.putExtra("esercizio", es);
    mIntent.putExtra("timeStart", System.currentTimeMillis());
    startWakefulService(mContext, mIntent);
}

@Override
@Nullable
public IBinder onBind(Intent intent) {
    return null;
}

任何解决方案?方向?

我的代码:

1。设置CERDITIALS

_uploadRequest.ACL = AWSS3BucketCannedACLPublicReadWrite

2。配置

_uploadRequest.ACL = AWSS3BucketCannedACLPrivate

第3。创建上传请求

AWSCognitoCredentialsProvider *credentialsProvider = [[AWSCognitoCredentialsProvider alloc]
initWithRegionType:_regionType
identityPoolId:_pool_id];

4。 START Transfer MANAGER

AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc]initWithRegion:_regionType credentialsProvider:credentialsProvider];    
AWSServiceManager.defaultServiceManager.defaultServiceConfiguration = configuration;
  • 存储区权限是读/写(适用于所有用户)

enter image description here

BUCKET POLICY:

_uploadRequest = [AWSS3TransferManagerUploadRequest new];
_uploadRequest.ACL = AWSS3BucketCannedACLPublicReadWrite;

1 个答案:

答案 0 :(得分:0)

在你的&#34;资源&#34;的末尾添加*线 (在您的存储桶政策中)

arn:aws:s3:::{bucketName}/{Folder}/*