如何在 amazon ios sdk 中为预签名 url 设置自定义端点?
How to set custom endpoints in amazon ios sdk for presigning urls?
我正在尝试从亚马逊服务器为这些音乐文件预签名 url,我有 android 的工作代码,但无法在 Objective-C 中找到执行此操作的方法.
public static String getPreSignedURL(String url) {
java.util.Date expiration = new java.util.Date();
long msec = expiration.getTime();
msec += 1000 * 60 * 5; // 5 minutes
expiration.setTime(msec);
AWSCredentials myCredentials = new BasicAWSCredentials(
AppConstants.AWS_ACCESS_KEY_ID, AppConstants.AWS_SECRET_KEY_ID);
AmazonS3 s3client = new AmazonS3Client(myCredentials);
s3client.setEndpoint(AppConstants.ENDPOINT_S3);
GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(
AppConstants.BUCKET_NAME, url.replace(AppConstants.OBJECT_NAME_FILTER, ""));
request.setExpiration(expiration);
URL objectURL = s3client.generatePresignedUrl(request);
return objectURL.toString();
}
以上代码在 android.
var presignedUrl: AWSTask = AWSTask()
let expiration = NSDate().dateByAddingTimeInterval(5*60)
let credential = AWSStaticCredentialsProvider.init(accessKey: AWS_ACCESS_KEY_ID, secretKey: AWS_SECRET_KEY_ID)
let configuration = AWSServiceConfiguration.init(region:.USEast1, credentialsProvider: credential)
//print("%@",configuration.endpoint)
//let regionTp = AWSRegionType(s)
AWSServiceManager.defaultServiceManager().defaultServiceConfiguration = configuration
let urlBuilder = AWSS3PreSignedURLBuilder.defaultS3PreSignedURLBuilder()
let preSignedURLRequest = AWSS3GetPreSignedURLRequest.init()
preSignedURLRequest.key = "10488/01-New_Jack_City_hq.mp3"
preSignedURLRequest.bucket = "damixhub"
preSignedURLRequest.expires = expiration
preSignedURLRequest.HTTPMethod = .GET
presignedUrl = urlBuilder.getPreSignedURL(preSignedURLRequest)
到目前为止,这就是我在 ios 中所做的,但是 url 有很大的不同,我收到拒绝访问错误可能是因为我没有提到自定义端点。
如果您知道解决方法,请告诉我。
我设法使用 amazon sdk 的版本 1 获得了它。
如果你正在使用 cocoa pods 只需写 pod "AWSiOSSDK" ,如果你想手动执行它那么你需要从 github get it here
注意 - 由于亚马逊在第 2 版 sdk 中不提供此功能,我必须使用这个已弃用的版本。
我正在尝试从亚马逊服务器为这些音乐文件预签名 url,我有 android 的工作代码,但无法在 Objective-C 中找到执行此操作的方法.
public static String getPreSignedURL(String url) {
java.util.Date expiration = new java.util.Date();
long msec = expiration.getTime();
msec += 1000 * 60 * 5; // 5 minutes
expiration.setTime(msec);
AWSCredentials myCredentials = new BasicAWSCredentials(
AppConstants.AWS_ACCESS_KEY_ID, AppConstants.AWS_SECRET_KEY_ID);
AmazonS3 s3client = new AmazonS3Client(myCredentials);
s3client.setEndpoint(AppConstants.ENDPOINT_S3);
GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(
AppConstants.BUCKET_NAME, url.replace(AppConstants.OBJECT_NAME_FILTER, ""));
request.setExpiration(expiration);
URL objectURL = s3client.generatePresignedUrl(request);
return objectURL.toString();
}
以上代码在 android.
var presignedUrl: AWSTask = AWSTask()
let expiration = NSDate().dateByAddingTimeInterval(5*60)
let credential = AWSStaticCredentialsProvider.init(accessKey: AWS_ACCESS_KEY_ID, secretKey: AWS_SECRET_KEY_ID)
let configuration = AWSServiceConfiguration.init(region:.USEast1, credentialsProvider: credential)
//print("%@",configuration.endpoint)
//let regionTp = AWSRegionType(s)
AWSServiceManager.defaultServiceManager().defaultServiceConfiguration = configuration
let urlBuilder = AWSS3PreSignedURLBuilder.defaultS3PreSignedURLBuilder()
let preSignedURLRequest = AWSS3GetPreSignedURLRequest.init()
preSignedURLRequest.key = "10488/01-New_Jack_City_hq.mp3"
preSignedURLRequest.bucket = "damixhub"
preSignedURLRequest.expires = expiration
preSignedURLRequest.HTTPMethod = .GET
presignedUrl = urlBuilder.getPreSignedURL(preSignedURLRequest)
到目前为止,这就是我在 ios 中所做的,但是 url 有很大的不同,我收到拒绝访问错误可能是因为我没有提到自定义端点。
如果您知道解决方法,请告诉我。
我设法使用 amazon sdk 的版本 1 获得了它。 如果你正在使用 cocoa pods 只需写 pod "AWSiOSSDK" ,如果你想手动执行它那么你需要从 github get it here
注意 - 由于亚马逊在第 2 版 sdk 中不提供此功能,我必须使用这个已弃用的版本。