最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

照片未上传到后端

网站源码admin21浏览0评论

照片未上传到后端

照片未上传到后端

我已经创建了后端,以使用在Postman上运行的post方法获取文件。

但是从angular2前端无法正常工作,这是我完成的服务代码。

data1是图像数据

addData(postData: Image, data1:any): Observable<Team[]> {
    console.log("team service");   
        this.image= postData;
        let body = this.image;


        let headers2= new Headers({ 'Content-Type': 'multipart/form-data' });
        let options = new RequestOptions({ headers: headers });


        return this.http.post(this.actionUrl, data1, options)
                .map(this.extractData)
                .catch(this.handleError);       
    }

它给出了错误:

POST http:// localhost:8080 / user / 45646 / userName / userPhoto 500(内部服务器错误)500-内部服务器错误

回答如下:

这是我用来通过RestAPI发布数据的方式,它正在起作用...

希望下面的示例代码对您有所帮助。

private httpCreate(data: T): Promise<T> {
    let headers = new Headers({'Content-Type': 'application/json'})
    return this.http.post(this.getUrl(), JSON.stringify(data), {headers: headers}).toPromise().then(res => res.json()).catch(this.handleError)
}

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论