AlamoFire 5.0 / PHP代码/上传1张图片

时间:2020-02-16 08:18:35

标签: alamofire ios13

我的目标是将1张图片从iPhone上传到我的Web服务器。我正在使用AlamoFire。通过使用W3Schools的信息,我有了可以用于网站上载到服务器的代码,并且可以正常工作。

<form action="upload.php" method="post" enctype="multipart/form-data">
   Select image to upload:
   <input type="file" name="fileToUpload" id="fileToUpload">
   <input type="submit" value="Upload Image" name="submit">
</form>

所以我想从捆绑包“ Green.jpg”上传文件。我认为它需要“ name = fileToUpload”,但是我不确定它在哪里。我猜它是multipartFormData的一部分,但我不确定。

   let fileURL = Bundle.main.url(forResource: "Green", withExtension: "jpg")!

    AF.upload(fileURL, to: "https://example.com/Shadow/upload.php")
        .uploadProgress { progress in
            print("Upload Progress: \(progress.fractionCompleted)")
    }
    .responseJSON { response in
        debugPrint(response.response!)
    }

0 个答案:

没有答案