انتقل إلى المحتوى
أمين أبوزيد
درس مخطط لهJNR-023-L03

البث عند التنزيل

  • الدرس 3 من 6
  • Junior
في هذا الدرس 4 موضوعات

هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.

نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.

في هذا الدرس

send big files without loading them into memory.

الموضوعات المخطط لها

  • Reading a whole file into a byte[] uses memory per request; ten parallel downloads can crash the server.
  • Return a Resource (for example FileSystemResource) or a StreamingResponseBody; Spring copies it in chunks.
  • Set Content-Type from your stored record, and Content-Length when known.
  • Content-Disposition: attachment; filename="..." makes browsers download; inline displays.
  • Return 404 if the file record or file is missing.
تفاصيل المخطط المبدئي

عرض عملي

java
@GetMapping("/images/{id}")
ResponseEntity<Resource> download(@PathVariable String id) {
    Resource r = storage.load(id);
    return ResponseEntity.ok().contentType(MediaType.IMAGE_PNG).body(r);
}

اختبر فهمك

Why not return a byte[]?

أظهر الإجابة

The whole file sits in memory for each request.

التطبيق

طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.

المختبر والتمارين الاختبار

تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.

اكتب للبحث في المستويات والمراحل والوحدات والدروس.