使用Alamofire中的深层参数上传图像

问题描述 投票:0回答:1

如何在Alamofire上传这种参数的图像

{
    "user_email":"[email protected]",
    "user_token":"yiDmaVs6Ax-zUj1cM-Eh",
    "claim_id": 6,
    "items":[{
        "name":"Watch",
        "name_of_owner": "Selena Gomez",
        "phone_of_owner": "091237462",
        "email_of_owner": "[email protected]",
        "quantity":1,
        "is_owned": false, 
        "photo":"image data here..."
    },{
        "name":"iMac",
        "name_of_owner": "Steff Gomez",
        "phone_of_owner": "091237462",
        "email_of_owner": "[email protected]",
        "quantity":1,
        "is_owned": false,
        "photo": "image data here..."
    }]

}

如果您认为这不是我们应该如何处理每个项目的图像上传的最佳做法。请各位赐教。

swift file-upload parameter-passing alamofire multipartform-data
1个回答
0
投票

试试这样吧

    var bannerImage = [[String:AnyObject]]()
    var fileIDSArr = [String]() // these are how many images you want to load
    for i in 0..<fileIDSArr.count
    {
        let imageId:String = fileIDSArr[i]
        bannerImage.append([ "name":"Watch" as AnyObject,
                             "name_of_owner": "Selena Gomez" as AnyObject,
                             "phone_of_owner": "091237462" as AnyObject,
                             "email_of_owner": "[email protected]" as AnyObject,
                             "quantity":1 as AnyObject,
                             "is_owned": false as AnyObject,
                             "photo":"image data here..." as AnyObject])
    }

    var params = [String:Any]()
    params = ["user_email":"[email protected]",
              "user_token":"yiDmaVs6Ax-zUj1cM-Eh",
              "claim_id": 6,
              "items":bannerImage]
© www.soinside.com 2019 - 2024. All rights reserved.