1- convert each image into data and encoded a base64 format and zip it :
let strBase64 = imageData.base64EncodedString(options: .lineLength64Characters)
print(strBase64)
zip string using chilkat : https://www.example-code.com/swift/compress_decompress_string.asp
func chilkatTest() {
// This example requires the Chilkat API to have been previously unlocked.
// See Compression UnlockComponent for sample code.
var success: Bool
let sb = CkoStringBuilder()
var i: Int
for i = 1; i <= 20; i++ {
sb.Append("This is the original uncompressed string.\r\n")
}
let compress = CkoCompression()
compress.Algorithm = "deflate"
// Indicate that the utf-8 byte representation of the string should be compressed.
compress.Charset = "utf-8"
var compressedBytes: NSData
compressedBytes = compress.CompressString(sb.GetAsString())
// If the compressed data is desired in string format, then get the base64 representation of the bytes.
compress.EncodingMode = "base64"
var compressedBase64: String? = compress.CompressStringENC(sb.GetAsString())
print("Compressed Bytes as Base64: \(compressedBase64!)")
// Now decompress...
var decompressedString: String? = compress.DecompressString(compressedBytes)
print("The original string after decompressing from binary compressed data:")
print("\(decompressedString!)")
// To decompress from Base64...
compress.EncodingMode = "base64"
decompressedString = compress.DecompressStringENC(compressedBase64)
print("The original string after decompressing from Base64:")
print("\(decompressedString!)")
}
2- save it in json format :
[
{"1": "strBase64FromStep1"},
{"2": "strBase64FromStep1"},
.
.
.
]
3- save the json String to text file :
let file = "file.txt" //this is the file. we will write to and read from it
let text = "some text" //just a text
if let dir = FileManager.default.urls(for: .documentDirectory, in:
.userDomainMask).first {
let fileURL = dir.appendingPathComponent(file)
//writing
do {
try text.write(to: fileURL, atomically: false, encoding: .utf8)
}
catch {/* error handling here */}
//reading
do {
let text2 = try String(contentsOf: fileURL, encoding: .utf8)
}
catch {/* error handling here */}
}
4- save your file url to UserDefaults :
fileURL From step 3
NSUserDefaults.standardUserDefaults().setObject(fileURL, forKey: "path")
NSUserDefaults.standardUserDefaults().synchronize()
5 - use this file any time you want to send to server .