1
func sendFiles(fileURLs: [URL], studentID: String, assignmentID: Int) {
        let endpoint = "http://192.168.10.101:8000/course/file_assigment/"
        
        let headers: HTTPHeaders = [
            "Content-type": "multipart/form-data"
        ]
        
        AF.upload(multipartFormData: { multipartFormData in
            for (index, fileURL) in fileURLs.enumerated() {
                multipartFormData.append(fileURL, withName: "file[\(index)]")
            }
            
            multipartFormData.append(studentID.data(using: .utf8)!, withName: "studentID")
            multipartFormData.append("\(assignmentID)".data(using: .utf8)!, withName: "assignmentID")
        }, to: endpoint, headers: headers)
        .responseJSON { response in
            switch response.result {
            case .success(let value):
                print("Response: \(value)")
                // Handle success response
                
            case .failure(let error):
                print("Error: \(error.localizedDescription)")
                // Handle error
            }
        }
    }

URL: file:///var/mobile/Containers/Data/Application/804E4310-9F7F-4E17-81B8-C7BC4C32E9BE/Documents/sample.pdf Error: Error Domain=NSCocoaErrorDomain Code=260 "The file “sample.pdf” couldn’t be opened because there is no such file." UserInfo={NSURL=file:///var/mobile/Containers/Data/Application/804E4310-9F7F-4E17-81B8-C7BC4C32E9BE/Documents/sample.pdf, NSFilePath=/var/mobile/Containers/Data/Application/804E4310-9F7F-4E17-81B8-C7BC4C32E9BE/Documents/sample.pdf, NSUnderlyingError=0x282d38ff0 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}

Joakim Danielson
  • 43,251
  • 5
  • 22
  • 52
  • And? Do you know for sure there is such a file at that path, is the url in the error message the one you expected it to be? Please add some context to your question, what have you tried, what did you expect etc, etc. – Joakim Danielson Jun 22 '23 at 08:25
  • How did you create `fileURLs`? How do you know you have a file there? – Larme Jun 22 '23 at 08:28

0 Answers0