Skip to content

Upload videos , images and other files(pdf, doc,..) using MultiPart class Swift

License

Notifications You must be signed in to change notification settings

Datt1994/DPMultiPartSwift

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 

Repository files navigation

DPMultiPartSwift

Language: Swift 5 License

Upload videos , images and other files(pdf, doc,..) using MultiPart class Swift 4

For Objective C :- DPMultiPartObjC

Add Manually

Download Project and copy-paste MultiPart.swift file into your project

How to use

        let filePath = Bundle.main.url(forResource: "test", withExtension: "jpg")?.path
        
        let dicParameetrs = ["a_id": "1", "name": "Datt"]
        
        let arrFiles = [
            [MultiPart.fieldName: "images[]",/*(if only 1 file upload don't use [])*/
             MultiPart.pathURLs: [filePath, filePath]],
            [MultiPart.fieldName: "video",
             MultiPart.pathURLs: ["/Users/xyz/.../abc.mp4"]],
            [MultiPart.fieldName: "pdf[]",
             MultiPart.pathURLs: ["/Users/xyz/.../xyz.pdf", "/Users/xyz/.../h.pdf"]]
        ]
        // With JSON Object
        MultiPart().callPostWebService("http://www.xyz.com/../..", parameetrs: dicParameetrs, filePathArr: arrFiles) { (dic, error) in
            
            if (error == nil) {
                print(error ?? "")
            }
            
        }
        // With Model Object
        MultiPart().callPostWSWithModel("http://www.xyz.com/../..", parameters: dicParameetrs, filePathArr: arrFiles, model: LoginModel.self) {
            result in
            switch result {
            case .success(let response):
                print(response)
            case .failure(let failureResponse):
                print(failureResponse.message ?? "")
            case .error(let e):
                print(e ?? "")
            }
        }