تنبيه النظام

الرجاء تحديد نص من المقال أولاً لإنشاء بطاقة المشاركة.

1 / 10
Ahmed Bouchefra Profile Header
A.B

;Ahmed Bouchefra

1.2k منشورات
100k قارئ
9 كاتب

أنا أحمد بوشفرة، مبرمج ومؤلف تقني (Tech Author) متخصص في تبسيط مفاهيم البرمجة وتطوير الويب. منذ عام 2017، أقدّم محتوى موجّهًا للمبرمجين عبر موقع 10xdev blog، بالإضافة إلى منصّات مثل SitePoint وSmashing Magazine. أسلوبي عملي ويساعد المبرمجين على فهم التقنيات بسرعة وبناء مهارات قوية بثقة. كما تعاونت مع دار النشر Packt في إصدار كتاب Full Stack Development with Angular and GraphQL، مما يعكس جودة المحتوى الذي أقدمه للمبرمجين. يحتوي هذا الموقع على مقالات كتبتها للجمهور العربي، بالإضافة إلى مقالاتي المترجمة من موقع 10xdev blog ومقالات أخرى ساهم بها مبرمجون من مختلف الأنحاء.

Angular 9/8 Multiple File Uploading Service with Progress Report

جاهز

ملخص سريع للمقال باستخدام الذكاء الاصطناعي

إذا لم يكن لديك الوقت لقراءة المقال بالكامل، اضغط على زر نسخ لنسخ التوجيه (Prompt) أدناه، ثم اضغط على زر فتح ChatGPT للصقه هناك والحصول على أهم النقاط.

لخص هذا المقال واستخرج أهم النقاط (Key Takeaways) مع شرح المصطلحات التقنية. العنوان: Angular 9/8 Multiple File Uploading Service with Progress Report - الرابط:
https://www.ahmedbouchefra.com/angular-9-multiple-file-uploading-service-with-progress-report/

In this how-to tutorial, we’ll see how to build a multiple file/image uploading service with Angular 9 which allows you to upload files to a remote server via a POST request method to listen for progress events.

Prerequisites

We’ll only see how to implement the service for sending a POST request to upload files and listen for progress events but we’ll not create a project from scratch so you’ll need to install Angular CLI and initialize a project.

Step 1 - Creating an Angular Service

Open a new terminal and run the folowing command to generate a service:

$ ng generate service upload

Next, open the src/app/upload.service.ts file and import the following:

import { HttpClient, HttpEvent, HttpErrorResponse, HttpEventType } from  '@angular/common/http';  
import { map } from  'rxjs/operators';

Next, inject HttpClient via the service constructor:

@Injectable({  
  providedIn: 'root'  
})  
export class UploadService { 
	constructor(private httpClient: HttpClient) { }

Step 2 - Implementing the Upload Method

Next, add the upload() method which simply calls the post() method of HttpClient to send an HTTP POST request with form data to the file upload server:

public upload(fileData) {

	return this.httpClient.post<any>("https://file.io/", fileData, {  
      reportProgress: true,  
      observe: 'events'  
    });  
}

Conclusion

In this quick how-to article, we’ve implemented a service for uploading files to a server and listenning for progress events.