在Angular中成功发布后的HttpErrorResponse 200

编程入门 行业动态 更新时间:2024-10-06 18:28:35
本文介绍了在Angular中成功发布后的HttpErrorResponse 200的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我通过 FormData 将一个文件从 Angular 5.xx 上传到 Jersey 1.xx.

I upload one file from Angular 5.xx to Jersey 1.xx via FormData.

数据已成功接收并保存在我的服务器应用程序目录中,但浏览器从图片中说出这一行(Chrome 和 Firefox).

The data gets received and saved successfully on my server app directory, but Browser says this line from the picture (Chrome and Firefox).

当我像这样通过 HTML 上传它时:

When I upload it via HTML only like so:

Choose file to upload<br> <form action="localhost:8181/BackendMaven" method="post" enctype="multipart/form-data"> <input name="input" id="filename" type="file" /><br><br> <button name="submit" type="submit">Upload</button> </form>

它不会出现.

这是角度 FromData 代码:

Here is the angular FromData Code:

@ViewChild('fileInput') fileInput; submitFile(): void{ console.log("submitFIle called!!!"); let fi = this.fileInput.nativeElement; let fileToUpload = fi.files[0]; let formData = new FormData();//empty formdata formData.append("input", fileToUpload); console.log(formData.get("input")); this.http.post(this.URI_UPLOAD,formData).subscribe();}

和服务器端(我使用tomcat)

And Server Side (im using tomcat)

public Response uploadFile(@FormDataParam("input") InputStream uploadedInputStream, @FormDataParam("input") FormDataContentDisposition fileDetail) { ... return Response.status(200).entity("Successfully uploaded to location: " + FileFactory.getFilePath(uploadedFileLocation)).build(); } }

推荐答案

尝试实际发送 JSON 响应,或者告诉 Angular 期待不同的东西.如果您使用 HttpClient,默认情况下会使用 JSON.

Try to actually send a JSON response, or tell angular to expect something different. If you're using HttpClient, it will by default expect JSON.

类似这样的:

this.http.post(url, body, { responseType: 'text' }).subscribe();

更多推荐

在Angular中成功发布后的HttpErrorResponse 200

本文发布于:2023-10-10 18:18:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1479359.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Angular   HttpErrorResponse

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!