提问人:narner 提问时间:5/14/2021 更新时间:5/14/2021 访问量:161
在 for 循环中按顺序将 Swift 中的图像数组上传到 S3
Uploading Array of Images in Swift to S3 Sequentially in a For-Loop
问:
我有一个数组 ',我想将其上传到 Swift 中的 S3 实例。以下是我上传它们的代码:UIImage
func sendImageMessage(photo : UIImage) {
s3Uploader.uploadFile(withImage: photo) { [self] (url) in
processMessage(ourShip: ourShip!, shipUrlString: shipURLString, chatShip: airlockStore.selectedChannel.channelShip, chatName: airlockStore.selectedChannel.channelName, text: url, index: idx)
sendPendingMessage(text: url)
}
}
这是我的代码,我从聊天视图中的相机输入栏获取图像数组:
func inputBar(_ inputBar: InputBarAccessoryView, didPressSendButtonWith attachments: [AttachmentManager.Attachment]) {
for item in attachments {
if case .image(let image) = item {
self.sendImageMessage(photo: image)
}
}
inputBar.invalidatePlugins()
}
我遇到的问题是,如果选择了多个图像,则在第一项完成上传之前,会再次调用每个项目。sendImageMessage
我尝试使用闭包来暂停我的循环,直到上传第一个项目之前,不要转到图像数组中的下一个项目,但无法让它工作。
答: 暂无答案
评论
DispatchGroup