如何使用加速端点将文件上传到 swift 中的 s3
How to upload file to s3 in swift using accelerated endpoint
我想使用 aws swift sdk
上传文件到 s3
我这样注册了 awsTransferUtility
// in app delegate
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [
UIApplication.LaunchOptionsKey: Any
]?) -> Bool {
let configuration = AWSServiceConfiguration(region:.APSoutheast1, credentialsProvider:credentialsProvider)
AWSS3TransferUtility.register(
with: configuration,
forKey: "east1"
)
}
在我的函数中,我调用了这样的传输实用程序
let transferUtility = AWSS3TransferUtility.s3TransferUtility(forKey: endpoint.rawValue)!
transferUtility.uploadData(
data,
bucket: bucket,
key: uploadPath,
contentType: "text/plain",
expression: expression, completionHandler:
completionHandler).continueWith {
(task) -> AnyObject? in
guard task.error == nil else {debugPrint(task.error!); return nil}
if let result = task.result {
debugPrint(result)
}
return nil
}
这有效,但它是使用标准端点上传的。如何使用加速端点上传?
当您初始化传输实用程序对象时,在应用委托中,您可以添加使用加速端点的选项
let s3config = AWSS3TransferUtilityConfiguration()
s3config.isAccelerateModeEnabled = true
AWSS3TransferUtility.register(
with: configuration,
transferUtilityConfiguration: s3config,
forKey: "east1"
)
然后就可以正常调用上传了,会用到加速端点
我想使用 aws swift sdk
上传文件到 s3我这样注册了 awsTransferUtility
// in app delegate
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [
UIApplication.LaunchOptionsKey: Any
]?) -> Bool {
let configuration = AWSServiceConfiguration(region:.APSoutheast1, credentialsProvider:credentialsProvider)
AWSS3TransferUtility.register(
with: configuration,
forKey: "east1"
)
}
在我的函数中,我调用了这样的传输实用程序
let transferUtility = AWSS3TransferUtility.s3TransferUtility(forKey: endpoint.rawValue)!
transferUtility.uploadData(
data,
bucket: bucket,
key: uploadPath,
contentType: "text/plain",
expression: expression, completionHandler:
completionHandler).continueWith {
(task) -> AnyObject? in
guard task.error == nil else {debugPrint(task.error!); return nil}
if let result = task.result {
debugPrint(result)
}
return nil
}
这有效,但它是使用标准端点上传的。如何使用加速端点上传?
当您初始化传输实用程序对象时,在应用委托中,您可以添加使用加速端点的选项
let s3config = AWSS3TransferUtilityConfiguration()
s3config.isAccelerateModeEnabled = true
AWSS3TransferUtility.register(
with: configuration,
transferUtilityConfiguration: s3config,
forKey: "east1"
)
然后就可以正常调用上传了,会用到加速端点