I am trying to post a file ( uploaded file ) to backed. getting this error.
Failed to load http://52.7.92.114:8080/cms-m2ts/rest/DocumentTagService/uploadFile: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access.
How to come up with this? here is my service in angular: please correct me wherever I am wrong. But the above stuff works without any issue in postman
import { Injectable } from '@angular/core';
import { Http, Headers, RequestOptions } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
@Injectable()
export class DocUploadService {
baseUrl: string = 'http://52.7.92.114:8080/cms-m2ts/rest/DocumentTagService';
constructor(private http:Http) { }
uploadDocument(file:File):Observable<File>{
const headers = new Headers();
headers.append('Content-Type', 'application/json');
let options = new RequestOptions({ headers: headers, body:{"tagCount" : 5 } });
const url = `${this.baseUrl}/uploadFile`;
return this.http.post(url, file, options ).map(response => response.json())
}
}