釣魚術
swift
AWS
Amplify
Pod 'AmplifyPlugins/AWSS3StoragePlugin'
pod install --repo-update
來安裝我們後面加進來的套件。如果你沒裝的話,上面那個範例自然一動也不動。import AWSS3StoragePlugin
func uploadStamp() {
let fileKey = "fish_test.txt"
let fileContents = "This is SPADA!!!"
let fileData = fileContents.data(using: .utf8)!
Amplify.Storage.uploadData(
key: fileKey,
data: fileData
) { result in
switch result {
case .success(let key):
print("file with key \(key) uploaded")
DispatchQueue.main.async {
self.fileStatus = "File uploaded"
}
case .failure(let storageError):
print("Failed to upload file", storageError)
DispatchQueue.main.async {
self.fileStatus = "Failed to upload file"
}
}
}
}