我正在尝试从亚马逊服务器获取这些音乐文件的预签名网址,我有工作的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中所做的事情,但是网址有很大差异,我可能因为我没有提到自定义端点而获得访问错误。
如果你知道解决方法,请告诉我。
答案 0 :(得分:0)
我设法使用amazon sdk的第1版获得此功能。 只需编写pod" AWSiOSSDK"如果您正在使用可可豆荚,如果您想手动操作,那么您需要从github get it here获取它
注意 - 由于亚马逊在sdk的第2版中没有提供此功能,我必须使用此弃用版本。