{"action":"created","issue":{"url":"https://api.github.com/repos/zfcampus/zf-content-negotiation/issues/89","repository_url":"https://api.github.com/repos/zfcampus/zf-content-negotiation","labels_url":"https://api.github.com/repos/zfcampus/zf-content-negotiation/issues/89/labels{/name}","comments_url":"https://api.github.com/repos/zfcampus/zf-content-negotiation/issues/89/comments","events_url":"https://api.github.com/repos/zfcampus/zf-content-negotiation/issues/89/events","html_url":"https://github.com/zfcampus/zf-content-negotiation/issues/89","id":261970105,"number":89,"title":"File uploading with PUT method with Method Override","user":{"login":"Channad","id":26352834,"avatar_url":"https://avatars0.githubusercontent.com/u/26352834?v=4","gravatar_id":"","url":"https://api.github.com/users/Channad","html_url":"https://github.com/Channad","followers_url":"https://api.github.com/users/Channad/followers","following_url":"https://api.github.com/users/Channad/following{/other_user}","gists_url":"https://api.github.com/users/Channad/gists{/gist_id}","starred_url":"https://api.github.com/users/Channad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Channad/subscriptions","organizations_url":"https://api.github.com/users/Channad/orgs","repos_url":"https://api.github.com/users/Channad/repos","events_url":"https://api.github.com/users/Channad/events{/privacy}","received_events_url":"https://api.github.com/users/Channad/received_events","type":"User","site_admin":false},"labels":[{"id":52213162,"url":"https://api.github.com/repos/zfcampus/zf-content-negotiation/labels/bug","name":"bug","color":"fc2929","default":true}],"state":"open","locked":false,"assignee":{"login":"ezimuel","id":475967,"avatar_url":"https://avatars2.githubusercontent.com/u/475967?v=4","gravatar_id":"","url":"https://api.github.com/users/ezimuel","html_url":"https://github.com/ezimuel","followers_url":"https://api.github.com/users/ezimuel/followers","following_url":"https://api.github.com/users/ezimuel/following{/other_user}","gists_url":"https://api.github.com/users/ezimuel/gists{/gist_id}","starred_url":"https://api.github.com/users/ezimuel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ezimuel/subscriptions","organizations_url":"https://api.github.com/users/ezimuel/orgs","repos_url":"https://api.github.com/users/ezimuel/repos","events_url":"https://api.github.com/users/ezimuel/events{/privacy}","received_events_url":"https://api.github.com/users/ezimuel/received_events","type":"User","site_admin":false},"assignees":[{"login":"ezimuel","id":475967,"avatar_url":"https://avatars2.githubusercontent.com/u/475967?v=4","gravatar_id":"","url":"https://api.github.com/users/ezimuel","html_url":"https://github.com/ezimuel","followers_url":"https://api.github.com/users/ezimuel/followers","following_url":"https://api.github.com/users/ezimuel/following{/other_user}","gists_url":"https://api.github.com/users/ezimuel/gists{/gist_id}","starred_url":"https://api.github.com/users/ezimuel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ezimuel/subscriptions","organizations_url":"https://api.github.com/users/ezimuel/orgs","repos_url":"https://api.github.com/users/ezimuel/repos","events_url":"https://api.github.com/users/ezimuel/events{/privacy}","received_events_url":"https://api.github.com/users/ezimuel/received_events","type":"User","site_admin":false}],"milestone":null,"comments":7,"created_at":"2017-10-02T02:39:49Z","updated_at":"2017-10-04T13:45:53Z","closed_at":null,"author_association":"NONE","body":"I am trying to upload a file in a form with other data fields provided via Angular 4. With lot of difficulty I managed to get it posting properly. It requires that I remove the `Content-Type` header from the ajax posting.\r\n\r\nSo now both POST and PUT works as normally. However I have encountered a problem with apigility behavior when it comes to `X-HTTP-Method-Override` header. The POST method still works fine but PUT fails on input validation. Apigility reports all my required fields as empty when actually they are not.\r\n\r\nAs I said this happens only when I use POST with Method Overriding to PUT.\r\n\r\nAlso noticed that `allow_empty` and `continue_if_empty` does not work.\r\n\r\nMy production server does not support PUT & DELETE methods. So I need to get this working.\r\n\r\nMy `module.config.php` has the following for the specific file upload field:\r\n\r\n```php\r\n6 => [\r\n    'name' => 'projProposal',\r\n    'required' => false,\r\n    'filters' => [\r\n        0 => [\r\n            'name' => \\Zend\\Filter\\File\\RenameUpload::class,\r\n            'options' => [\r\n                'target' => 'data/uploads/projects/',\r\n                'use_upload_extension' => true,\r\n                'randomize' => true,\r\n            ],\r\n        ],\r\n    ],\r\n    'validators' => [\r\n        0 => [\r\n            'name' => \\Zend\\Validator\\File\\MimeType::class,\r\n            'options' => [\r\n                'mimeType' => 'pdf,doc,docx,xls,xlsx,application/vnd.openxmlformats-officedocument.wordprocessingml.document,enxmlformats-officedocument.spreadsheetml.sheet',\r\n            ],\r\n        ],\r\n        1 => [\r\n            'name' => \\Zend\\Validator\\File\\Size::class,\r\n            'options' => [\r\n                'max' => '10485760',\r\n            ],\r\n        ],\r\n    ],\r\n    'type' => \\Zend\\InputFilter\\FileInput::class,\r\n    'allow_empty' => false,\r\n    'continue_if_empty' => true,\r\n    'error_message' => 'Upload Failed.....',\r\n],\r\n```\r\n\r\nMy Template has the following among others:\r\n\r\n```html\r\n<form (ngSubmit)=\"onSubmit(dataRecord)\" #entryForm=\"ngForm\">\r\n  <div class=\"form-group \" *ngIf=\"(action !== 'View') || (action !== 'Delete')\">\r\n    <label for=\"projProposal\">Upload project proposal</label> \r\n    <input type=\"file\"\r\n      class=\"form-control\" id=\"projProposal\"\r\n      title=\"Upload files of type .pdf,.doc,.docx\" \r\naccept=\".pdf,.doc,.docx\"\r\n      name=\"projProposal\"\r\n      minlength=\"1\"\r\n      maxlength=\"500\"\r\n      size=\"5em\"\r\n      [readonly]=\"(action === 'View') || (action === 'Delete')\">\r\n    <div *ngIf=\"formErrors.projProposal\" class=\"alert alert-danger\">{{\r\n      formErrors.projProposal }}</div>\r\n  </div>\r\n</form>\r\n```\r\n\r\nMy data service has the following:\r\n\r\n```javascript\r\neditRecord (data: any): Observable<Response> {\r\n  let url = this._url + '/' + data.get('projectId');\r\n  const headers = new Headers({ 'Accept': '*/*',\r\n    'X-HTTP-Method-Override': 'PUT', // Not required if the server support PUT method\r\n    'Authorization': (this.authService.authresponse.token_type + ' ' + this.authService.getToken())\r\n  });\r\n  const options = new RequestOptions({ headers: headers});\r\n  return this.http.post(url, data, options)\r\n                  .map(this.extractData)\r\n                  .catch(this.handleError);\r\n}\r\n```\r\n\r\nThe Response I get is:\r\n\r\n```json\r\n{\r\n  \"validation_messages\": {\r\n    \"projDesc\": {\r\n      \"isEmpty\": \"Value is required and can't be empty\"\r\n    },\r\n    \"projCategory\": {\r\n        \"isEmpty\":\"Value is required and can't be empty\"\r\n    },\r\n    \"projStart\": {\r\n      \"isEmpty\":\"Value is required and can't be empty\"\r\n    },\r\n    \"projEnd\": {\r\n      \"isEmpty\": \"Value is required and can't be empty\"\r\n    },\r\n    \"createdOn\": {\r\n      \"isEmpty\": \"Value is required and can't be empty\"\r\n    },\r\n    \"createdBy\": {\r\n      \"isEmpty\": \"Value is required and can't be empty\"\r\n    }\r\n  },\r\n  \"type\": \"http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html\",\r\n  \"title\":\"Unprocessable Entity\",\r\n  \"status\":422,\r\n  \"detail\":\"Failed Validation\"\r\n}\r\n```\r\n\r\nMy Browser says this\r\n\r\n```http\r\nAccept:*/*\r\nAccept-Encoding:gzip, deflate\r\nAccept-Language:en-GB,en-US;q=0.8,en;q=0.6\r\nAuthorization:Bearer 4ef85a6aea3bdfd5e9a19bd28df145254c6e8133\r\nConnection:keep-alive\r\nContent-Length:73442\r\nContent-Type:multipart/form-data; boundary=----WebKitFormBoundaryAPvdSnxwn6DQnYdP\r\nHost:192.168.2.21\r\nOrigin:http://localhost:4200\r\nReferer:http://localhost:4200/projectDefinitions/edit/4;mode=Edit;showPage=1;showRows=11;filters=%7B%7D\r\nUser-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36\r\nX-HTTP-Method-Override:PUT\r\n\r\n------WebKitFormBoundaryAPvdSnxwn6DQnYdP\r\nContent-Disposition: form-data; name=\"projectId\"\r\n\r\n4\r\n------WebKitFormBoundaryAPvdSnxwn6DQnYdP\r\nContent-Disposition: form-data; name=\"projDesc\"\r\n\r\nSapiri Gevathu\r\n------WebKitFormBoundaryAPvdSnxwn6DQnYdP\r\nContent-Disposition: form-data; name=\"projCategory\"\r\n\r\n3002\r\n------WebKitFormBoundaryAPvdSnxwn6DQnYdP\r\nContent-Disposition: form-data; name=\"projStart\"\r\n\r\n2017-01-01\r\n------WebKitFormBoundaryAPvdSnxwn6DQnYdP\r\nContent-Disposition: form-data; name=\"projEnd\"\r\n\r\n2017-12-30\r\n------WebKitFormBoundaryAPvdSnxwn6DQnYdP\r\nContent-Disposition: form-data; name=\"applSeason\"\r\n\r\n1\r\n------WebKitFormBoundaryAPvdSnxwn6DQnYdP\r\nContent-Disposition: form-data; name=\"projObjectives\"\r\n\r\nObjective Two\r\n------WebKitFormBoundaryAPvdSnxwn6DQnYdP\r\nContent-Disposition: form-data; name=\"projProposal\"; filename=\"AGREEMENT-new.pdf\"\r\nContent-Type: application/pdf\r\n\r\n\r\n------WebKitFormBoundaryAPvdSnxwn6DQnYdP\r\nContent-Disposition: form-data; name=\"createdOn\"\r\n\r\n2017-09-29 08:48:31\r\n------WebKitFormBoundaryAPvdSnxwn6DQnYdP\r\nContent-Disposition: form-data; name=\"createdBy\"\r\n\r\nuser\r\n------WebKitFormBoundaryAPvdSnxwn6DQnYdP\r\nContent-Disposition: form-data; name=\"modifiedOn\"\r\n\r\n2017-10-2 8:2:22\r\n------WebKitFormBoundaryAPvdSnxwn6DQnYdP\r\nContent-Disposition: form-data; name=\"modifiedBy\"\r\n\r\nuser\r\n------WebKitFormBoundaryAPvdSnxwn6DQnYdP--\r\n```"},"comment":{"url":"https://api.github.com/repos/zfcampus/zf-content-negotiation/issues/comments/334160057","html_url":"https://github.com/zfcampus/zf-content-negotiation/issues/89#issuecomment-334160057","issue_url":"https://api.github.com/repos/zfcampus/zf-content-negotiation/issues/89","id":334160057,"user":{"login":"Channad","id":26352834,"avatar_url":"https://avatars0.githubusercontent.com/u/26352834?v=4","gravatar_id":"","url":"https://api.github.com/users/Channad","html_url":"https://github.com/Channad","followers_url":"https://api.github.com/users/Channad/followers","following_url":"https://api.github.com/users/Channad/following{/other_user}","gists_url":"https://api.github.com/users/Channad/gists{/gist_id}","starred_url":"https://api.github.com/users/Channad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Channad/subscriptions","organizations_url":"https://api.github.com/users/Channad/orgs","repos_url":"https://api.github.com/users/Channad/repos","events_url":"https://api.github.com/users/Channad/events{/privacy}","received_events_url":"https://api.github.com/users/Channad/received_events","type":"User","site_admin":false},"created_at":"2017-10-04T13:45:53Z","updated_at":"2017-10-04T13:45:53Z","author_association":"NONE","body":" @ezimuel \r\nHi Enrico,\r\n\r\nRE `Allow_Empty` and `continue_if_empty` flags, it looks like the system does not check what the value of the flags are but just if the flags are there or not. \r\n\r\nIf I need to allow empty on the file upload, I should remove the `allow_empty` and `continue_if_empty` flags from the module.config.php\r\n\r\nBest regards\r\nChanna"}}
{"actor":{"display_login":"Channad"}}