I am writing an application in Angular and should upload a file. The network shows me the status: 200, but there is no answer, and my end does not receive any file.
The problem is that 1. 1. Why is the request method OPTION? (CORS may have something to do with this! But I tested on a different machine where CORS is not a problem, since it is on the same port)
2.How to change Content-Type from / plain text to multipart / form-data when using file upload code?
- where I can determine the headers or content type using the file upload code http://valor-software.com/ng2-file-upload/ or http://ng2-uploader.com/docs code
This is a network report from a browser when using a file downloader:
Request URL:http://localhost:5000/clari5-cc/rest/1.0/installation/upload
Request Method:OPTIONS
Status Code:200 OK
Remote Address:[::1]:5000
Response Headers
view source
Allow:POST, OPTIONS
Content-Type:text/plain
Request Headers
view source
Accept:*/*
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
Access-Control-Request-Headers:
Access-Control-Request-Method:POST
Connection:keep-alive
Host:localhost:5000
Origin:http://evil.com/
Referer:http://localhost:3000/
But my old running application used to get this data in Network Response: I see a noticeable difference.
Request URL:http://localhost:5000/try/rest/1.0/installation/upload
Request Method:POST
Status Code:200 OK
Remote Address:[::1]:5000
Response Headers
view source
Content-Type:application/json
Transfer-Encoding:chunked
Request Headers
view source
Accept:application/json, text/javascript, */*; q=0.01
Accept-Encoding:gzip, deflate
Content-Type:multipart/form-data; boundary=---- WebKitFormBoundaryB06sfkK4FgTODz0F
Cookie:Webstorm-e27c5fb2=42da3160-45c3-490c-a5d9-b0ed07b63022
Host:localhost:5000
Origin:http://evil.com/
Referer:http://localhost:5000/try/mainPage.html
Request Payload
------WebKitFormBoundaryB06sfkK4FgTODz0F
Content-Disposition: form-data; name="uploadedFiles"; filename="installer.tar"
Content-Type: application/x-tar
here is the code and I don’t know how to make changes and there is no option, and also no example? Any help and suggestion would be appreciated, thanks
export class AppComponent {
public uploader:FileUploader = new FileUploader({url: "http://localhost:5000/try/rest/1.0/installation/upload"});
public hasBaseDropZoneOver:boolean = false;
public hasAnotherDropZoneOver:boolean = false;
public fileOverBase(e:any):void {
this.hasBaseDropZoneOver = e;
}
public fileOverAnother(e:any):void {
this.hasAnotherDropZoneOver = e;
}
}
or
export class AppDemoComponent implements OnInit {
private zone: NgZone;
private basicOptions: Object;
private progress: number = 0;
private response: any = {};
ngOnInit() {
this.zone = new NgZone({ enableLongStackTrace: false });
this.basicOptions = {
url: 'http://api.ng2-uploader.com:10050/upload'
};
}
handleUpload(data: any): void {
this.zone.run(() => {
this.response = data;
this.progress = data.progress.percent / 100;
});
}
}