我正在尝试将多个图像上传到我用作iOS后端的Laravel 5.3网络应用程序。在网站上我可以上传图片等没有问题,使用原生PHP脚本,我可以将图像上传到网站上的文件夹,但我在使用Swift 3,Alamofire 4和后端Laravel 5.x时遇到了麻烦
当ios用户点击上传时,他们会导航到我后端的路由,该路由应该将文件(图像)从请求移动到servers文件夹,创建文件名等,然后在数据库中创建行。
我可以获得200的状态代码来击中路线,但我似乎无法
一个。通过laravels响应错误消息调试请求,我通常可以在其他Alamofire.request .get和.post方法中看到这些消息 B.将图像移动到服务器 或C.在db
中创建一行有人可以给我一些建议吗?我是一名自学成才的程序员
PHP:
// the $request holds the payload
public function store(Request $request) {
return $request;
// also tried
// $file = $request->file('file');
// $filename = $file->getClientOriginalName();
// $user = Auth::user();
// $file->move('uploads' . $user->id . '/photos', $filename;
// $user->create(['filename' => $filename .... etc]);
// $user->save();
// return redirect()->back();
斯威夫特3,Alamofire 4:
@IBAction func upload(_ sender:Any){
let URL = try! URLRequest(url: "https://mywebsite.com/store", method: .post)
Alamofire.upload(multipartFormData: { multipartFormData in
multipartFormData.append(self.imageData!, withName: "store", fileName: "test.png", mimeType: "image/png")
}, with: URL, encodingCompletion: {
encodingResult in
switch encodingResult {
case .success(let upload, _, _):
upload.responseData { response in
debugPrint("SUCCESS RESPONSE: \(response)")
debugPrint(response.debugDescription)
print(response)
print(response.data)
print(response.result)
print(response.request)
print(response.description)
print(response.debugDescription)
print(response.metrics)
}
case .failure(let encodingError):
// hide progressbas here
print("ERROR RESPONSE: \(encodingError)")
}
})
When I get a 200 html response, There is normally a Laravel web page that gets included here allowing room for debugging with the API I am trying to consume. But it is cut short and I don't know why
eg
(Response) <NSHTTPURLResponse: 0x60800003d3e0> { URL: websitegoeshere } { status code: 200, headers {
"Cache-Control" = "no-cache";
"Content-Encoding" = gzip;
"Content-Type" = "text/html; charset=UTF-8";
Date = "Sun, 08 Jan 2017 21:10:21 GMT";
Server = "nginx/1.11.5";
"Set-Cookie" = "XSRF-
.... rest of Laravel web-page for debugging usually goes here .
.... and yes it is enabled