【问题标题】:Photo not uploading to backend照片未上传到后端
【发布时间】:2016-09-23 11:58:36
【问题描述】:

我已经创建了后端以使用它在 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 - 内部服务器错误

【问题讨论】:

    标签: node.js api angular


    【解决方案1】:

    这是我用来通过 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)
    }
    

    【讨论】:

    • 它适用于 json 数据。我想使用 'form-data' 内容类型传递文件
    猜你喜欢
    • 2018-03-27
    • 1970-01-01
    • 1970-01-01
    • 2011-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多