How to upload zip data with alamofire?
Eventually, I found the issue, server side does not accept my request. Also, there is some confusion, because if I try to download an image file from my project it works, but if the file is selected from the document directory then there is an issue.
Anyway if someone has a similar issue try to check your server side.
Try to check if your request came to server and with content inside.
Download & Upload zip file
The following code works:
let data = try? NSData(contentsOf: URL(string:str)!) as Data
AF.upload(multipartFormData: { multipartFormData in
multipartFormData.append(data!,withName: "file",fileName: file_name ,mimeType: "application/octet-stream")
}, to: "http://"+dev.ipAddress+"/update")
.response { response in
if response.response?.statusCode != 200 {
devicesUpdateError.append(dev.name)
}
}
Swift How to Unzip file from URL with Alamofire and SSZipArchive
By looking at your code, the path you are using for the source is perfect.
For the destination path, try updating it to
func unzipPath(fileName:String) -> String? {
let path = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as NSString
let pathWithComponent = path.appendingPathComponent("test\(fileName)")
do {
try FileManager.default.createDirectory(atPath: pathWithComponent, withIntermediateDirectories: true, attributes: nil)
} catch {
return nil
}
return pathWithComponent
}
Try and share the results.
Related Topics
Error: Use of Unresolved Identifier 'Process'
Parameters After Opening Bracket
How to Add Kerning to a Textfield in Swiftui
How to Retrieve a Random Object from Firebase Using a Sequential Id
Checking If a Double Value Is an Integer - Swift
Swift Convert String to Unsafemutablepointer<Int8>
Passing Data from Tableview to Viewcontroller in Swift
Swift 3 (Spritekit): Reseting the Gamescene After the Game Ends
Can't Understand How Collision Bit Mask Works
How to Simulate Mouse Click from MAC App to Other Application
How to Open Your App in Settings iOS 11
Difference Between Associated and Raw Values in Swift Enumerations
Create Nsmanagedobject Subclass... Make a New Error in My Project
Check If Variable Is an Optional, and What Type It Wraps
What Does the '@' Symbol Mean in Swift
Cannot Invoke 'Join' with an Argument List of Type (String, [String]) in Swift 2.0