I have an array of UIImage
's that I want to upload to my S3 instance in Swift. Below is my code for uploading them:
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)
}
}
Here is my code where I'm getting the array of images from a camera input bar in a chat view:
func inputBar(_ inputBar: InputBarAccessoryView, didPressSendButtonWith attachments: [AttachmentManager.Attachment]) {
for item in attachments {
if case .image(let image) = item {
self.sendImageMessage(photo: image)
}
}
inputBar.invalidatePlugins()
}
The issue I'm having is that if multiple images are selected, the sendImageMessage
gets called again for each item before the first item has finished uploading.
I've tried using closures to pause my loop from going to the next item in the images array until the first one has been uploaded, but haven't been able to get this to work.