Angular Image Upload Made Easy
Why Stack Overflow recommends it
Stack Overflow users link it as the standard walkthrough for Angular file and image uploads, and cite it when debugging upload progress, multipart content-type headers and web API errors.
Recommended by 2 people across 2 different months, 2018 to 2021.
What it is
A 12-minute Angular tutorial from Academind that walks through uploading an image from an Angular app to a server using HttpClient and FormData. It is a short snippet-style lesson from a larger Angular course.
What people said
Recommends slevin · 2018-09 · Stack Overflow · on “Cannot properly set RequestOptionsArgs of POST, in service”
I use angular 6 and I was following along this video tutorial [this video] to submit images. I would like to observe the progress of the form submission, so I can get the percentage of the uploaded file. I have this in my component import { HttpClient,HttpEventType } from '@angular/common/http'; import { Http, Headers } from '@angular/http'; constructor( private formBuilder: FormBuilder, private myService:MyService, private changeDetector: ChangeDetectorRef, private carouselConfig : NgbCarouselConfig , private http:HttpClient ) { } let headers = new Headers(); headers.append('Authorization',this.token); let eb =null; this.http.post(' [LINK] ',formData,{reportProgress:true,observe:'events'}).subsc
Recommends Shorbagy · 2018-11 · Stack Overflow · on “Angular Ts update an element in for loop”
You can workaround by simulating a fake setTimeout because all of this happen in the front-end side so there might be no time at all. but you can make the progress bar pattern when you upload it to a backend so you will have a progress from the backend and you can display it. Follow this tutorial for uploading file to the server : [this video] Also don't use document.getElementById inside angular components best practice is to use the native element inside the component or make a ref in input field and reference it inside the component. For the technique you use it's preferable to use a boolean variable that controls this behavior and use [disabled] in the input field. I made this stackblitz that
Cites Adi L · 2018-06 · Stack Overflow · on “Upload file from angular 6 to web api”
Upload image from angular 6 to web api 2, i was success from postman but not from my angular app. i use many of tutorials like:1) [LINK] , 2) [this video] but Anytime I fall on if (!request.Content.IsMimeMultipartContent("form-data")) { return BadRequest("Unsupported media type"); } what am I missing? The only change is that in my Angular I use the Interceptor and the headers goes like: req = req.clone({ setHeaders: { 'Content-Type' : 'application/json; charset=utf-8', 'Accept' : 'application/json', 'Authorization': `Bearer ${decodedString}`, }, }); all the rest code are exacly like the first tutorial if you guys need more details, please let me know thanks
Cites Alex Cooper · 2020-05 · Stack Overflow · on “ContentType for HttpHeaders when uploading File in FormData”
I have an Angular Single Page Application which calls a .NET Core API. The default set up creates HttpHeaders to pass a jwt token to the API and sets the content-type to application/json; charset=utf-8 To extend this application, I've been following "Angular Image Upload Made Easy" ( [this video] ), but with my default headers, the image in FormData in the API was always null. So I changed the content-type to multipart/form-data , but got the same result. After much experimentation, I discovered that not setting a content-type at all works . I can still pass my jwt to authenticate the user and the image now uploads without any problems. So, is it safe to leave out content-type in request options,
Cites Thirumani · 2021-05 · Stack Overflow · on “Angular: reportProgress does not return data progressively”
I'm trying to display the progress bar of uploading images on my website. But I'm not getting the "loaded" value progressively in the HttpEvent response, so I'm not able to show the progress bar on the website progressively. I'm getting the "loaded" & "total" values as equal in my 1st event response, so then how can I use it for progressing UI. See my response in the screenshot. ScreenShot1 [LINK] My code is this.http.post<any>(' [LINK] ', uploadData, { reportProgress: true, observe: 'events' } ).subscribe(data => {console.log(data);}); See this screenshot, this is what I'm getting the response. Response in console window: ScreenShot1 [LINK] I followed some youtube videos, they are getting t