Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
To preview a selected image in Angular without uploading it, read the user-selected File from the file input, create a temporary browser URL with URL.createObjectURL(file), and bind that URL to an <img>. Keep the original File separately for the eventual upload, and revoke the temporary URL when the preview is replaced, cleared, or the component is destroyed.
Build a single-image preview
The file picker gives the page access to a file the user has chosen; it does not send that file to your server. The preview is a local display step. Upload only when the user submits the form or takes another explicit action.
Template
This template accepts image files, displays a preview when available, shows a validation message, and lets the user clear the selection:
<label for="image-file">Choose an image</label>
<input
id="image-file"
type="file"
accept="image/*"
(change)="onImageSelected($event)"
>
<p *ngIf="errorMessage" role="alert">{{ errorMessage }}</p>
<figure *ngIf="previewUrl">
<img [src]="previewUrl" alt="Preview of the selected image">
<figcaption>Preview only — the image has not been uploaded.</figcaption>
</figure>
<button type="button" (click)="clearPreview()" [disabled]="!selectedFile">
Clear image
</button>
The accept attribute guides the file picker; it is not a validation or security boundary. Check the chosen file in application code and validate again on the server before accepting an upload.
#1 Best Overall
- CRISP CLARITY: This 23.8″ Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
- INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
- THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
- WORK SEAMLESSLY: This sleek monitor is virtually bezel-free on three sides, so the screen looks even bigger for the viewer. This minimalistic design also allows for seamless multi-monitor setups that enhance your workflow and boost productivity
- A BETTER READING EXPERIENCE: For busy office workers, EasyRead mode provides a more paper-like experience for when viewing lengthy documents
Component logic and cleanup
Store the selected File separately from its preview URL. Revoke the old URL before replacing it, and clean up the active URL when the component is destroyed.
import { Component, OnDestroy } from '@angular/core';
@Component({
selector: 'app-image-picker',
templateUrl: './image-picker.component.html'
})
export class ImagePickerComponent implements OnDestroy {
previewUrl: string | null = null;
selectedFile: File | null = null;
errorMessage = '';
onImageSelected(event: Event): void {
const input = event.target as HTMLInputElement;
const file = input.files?.[0] ?? null;
this.releasePreview();
this.selectedFile = null;
this.errorMessage = '';
if (!file) return;
if (!file.type.startsWith('image/')) {
this.errorMessage = 'Choose an image file.';
input.value = '';
return;
}
this.selectedFile = file;
this.previewUrl = URL.createObjectURL(file);
}
clearPreview(): void {
this.releasePreview();
this.selectedFile = null;
this.errorMessage = '';
}
private releasePreview(): void {
if (this.previewUrl) {
URL.revokeObjectURL(this.previewUrl);
this.previewUrl = null;
}
}
ngOnDestroy(): void {
this.releasePreview();
}
}
This is a component pattern, not a guarantee for a particular Angular version or project setup; adapt the template to the Angular features already used by your application. If your form also needs a submit button, enable it only when selectedFile is set, and send that file in the submit handler. Do not use previewUrl as the upload payload: it is a browser-created reference for display.
What happens when a selection changes
When the user picks another file, the input emits another change event. The handler first releases the previous preview and clears the previous file, then either records the new valid file or shows an error. This ordering avoids accidentally submitting the prior image after a new, invalid selection.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Clear out junk files and repair common Windows errors3Fix the driver behind crashes, sound loss and screen glitchesRank #2
- CRISP CLARITY: This 22 inch class (21.5″ viewable) Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
- 100HZ FAST REFRESH RATE: 100Hz brings your favorite movies and video games to life. Stream, binge, and play effortlessly
- SMOOTH ACTION WITH ADAPTIVE-SYNC: Adaptive-Sync technology ensures fluid action sequences and rapid response time. Every frame will be rendered smoothly with crystal clarity and without stutter
- INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
- THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
Clearing only the component properties removes the visible preview, but the generated object URL should also be revoked. Conversely, do not revoke it immediately after assigning it to previewUrl: the image still needs that URL to render. Release it when the preview is no longer in use.
Validate selections and keep upload separate
File selection is a user-controlled boundary. The browser can give your page files the user selects through a file input or drag and drop; page scripts do not receive unrestricted access to arbitrary local paths. Treat the chosen File as input to validate, not as trusted content.
- Picker guidance: use
accept="image/*"for broadly accepted image types, or a narrower hint such asaccept="image/png,image/jpeg"if the product supports only those formats. - Application policy: check the selected file against the formats, size limits, or image-dimension rules your application actually requires. Show a useful error instead of silently discarding an invalid choice.
- Server acceptance: repeat security-relevant validation on the server. A client-side MIME-type check improves the user experience but does not establish that a file is safe or acceptable.
- Upload action: retain the original
Fileand send it only from the application’s upload or form-submit action. A working local preview is not evidence that a server received the image.
The example uses the browser-provided file.type as a convenient initial check. If it is empty or does not match your product’s requirements, report the issue and rely on your server’s own acceptance rules; do not broaden the server policy just to make the preview appear.
Rank #3
- Clear visuals. Fluid motion: A 144Hz refresh rate and 1ms MPRT deliver smooth, tear‑free motion across work, gaming, and streaming for clearer, more fluid viewing.
- Eye comfort: TÜV Rheinland 3‑star* certification reduces harmful blue light while preserving stunning color quality without compromise. *TÜV Rheinland 3-star eye comfort certification.
- Wide viewing angle: Get consistent views across a wide 178° /178° viewing angle.
- In-Plane Switching (IPS): See excellent color accuracy and consistency across wide viewing angles with In-plane Switching (IPS) technology.
- Ultra-thin bezels: Maximize your viewing experience with thin bezels.
Choose object URLs or FileReader
| Approach | What the image source is | Use it when | Lifecycle |
|---|---|---|---|
URL.createObjectURL(file) |
A temporary URL referring to the selected file | You need to display the selected image, without needing its contents as a data URL | Call URL.revokeObjectURL(url) when replacing, clearing, or disposing of the preview |
FileReader.readAsDataURL(file) |
A data: URL produced asynchronously after reading the file |
Later application logic specifically needs the data URL representation | Handle the reader’s load result and update or discard the resulting string with your component state |
For a basic image preview, an object URL is the direct option: it gives the <img> a source without first building a base64 data URL. Choose FileReader when the data URL itself serves a concrete need, rather than using it merely because the result can be assigned to src.
Recommended Free Tools
FileReader alternative
The same input can be read asynchronously with FileReader. Reset the existing preview first, then set the preview after the read completes:
onImageSelectedWithReader(event: Event): void {
const input = event.target as HTMLInputElement;
const file = input.files?.[0] ?? null;
this.releasePreview();
this.selectedFile = null;
this.errorMessage = '';
if (!file || !file.type.startsWith('image/')) {
this.errorMessage = file ? 'Choose an image file.' : '';
return;
}
const reader = new FileReader();
reader.addEventListener('load', () => {
if (typeof reader.result === 'string') {
this.selectedFile = file;
this.previewUrl = reader.result;
}
});
reader.addEventListener('error', () => {
this.errorMessage = 'The selected file could not be read.';
});
reader.readAsDataURL(file);
}
In this variant, previewUrl holds a data URL rather than an object URL, so there is no object URL to revoke. If users can change their selection while a read is in progress, ensure an older read cannot overwrite the newer selection; for example, track the latest request or cancel the prior reader. Keep the selected file associated with the result that actually completed.
Rank #4
- CURVED FOR ENHANCED ENGAGEMENT: An immersive viewing experience with a curved monitor that wraps more closely around your field of vision; It creates a wider view, enhancing depth perception and minimizing peripheral distraction
- SMOOTH PERFORMANCE FOR SEAMLESS CONTENT: Stay in the action when playing games, watching videos, or working on creative projects; The 100Hz refresh rate reduces lag and motion blur so you don't miss a thing in fast-paced moments¹
- MORE GAMING POWER: Gain the edge with optimizable game settings; Color and image contrast can be adjusted to see scenes more vividly and spot enemies hiding in the dark; Game Mode adjusts any game to fill the screen so you can view every detail²
- KEEP IT EASY ON THE EYES: Care for your eyes and stay comfortable, even during long sessions; Advanced eye comfort technology certified by TÜV reduces eye strain by minimizing blue light and reducing irritating screen flicker²
- INCREASED VERSATILITY: Connect to more; Plug devices straight into your monitor for increased flexibility, making your computing environment even more convenient
Preview multiple selected images
For a multiple-file input, add the multiple attribute and process the selected files. Keep each accepted file and preview URL together so removing one preview also releases its URL. The following illustrates the state shape and mapping:
interface ImagePreview {
file: File;
url: string;
}
previews: ImagePreview[] = [];
onImagesSelected(event: Event): void {
const input = event.target as HTMLInputElement;
this.clearImages();
const files = Array.from(input.files ?? []);
this.previews = files
.filter(file => file.type.startsWith('image/'))
.map(file => ({ file, url: URL.createObjectURL(file) }));
}
removeImage(index: number): void {
const [removed] = this.previews.splice(index, 1);
if (removed) URL.revokeObjectURL(removed.url);
}
clearImages(): void {
for (const preview of this.previews) {
URL.revokeObjectURL(preview.url);
}
this.previews = [];
}
ngOnDestroy(): void {
this.clearImages();
}
Bind each preview’s url to an image and retain its file for a later upload. In production, do not silently filter out invalid files if users need to know which selections were rejected; report each invalid choice or show a clear summary. Also apply the application’s own limits before attempting to preview a large batch.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Common problems and fixes
- No preview appears: confirm the change handler receives an event and that
input.files?.[0]contains a file. Check that the selected file passes the application check and that the template binds[src]="previewUrl". - A previous image remains after an invalid choice: clear the old preview and selected file at the beginning of the handler, before validating the new selection. The single-image example follows this order.
- The preview vanishes or fails after cleanup: do not revoke the object URL immediately after creating it. Revoke it only after removing or replacing the image, or when the component is destroyed.
- Repeated selection of the same file does not trigger a change: after handling the selection, clear the input value when the user needs to choose that same file again. Clear the component’s selected-file state only when that matches the interface behavior you intend.
- Image shows but upload does not work: rendering a local object URL is independent of network upload. Verify that the submit handler uses the retained
Fileand that the application sends it through its upload transport. - Some images are accepted in the browser but rejected by the server: align the user-facing checks with the server’s real format and size policy, while keeping the server authoritative. A picker hint or client check cannot guarantee server acceptance.
- One preview replaces another in a multi-file view: track each URL with its corresponding file and render the collection, rather than storing all selections in one scalar preview property.
Or skip the browser setup
ScreenshotNeo is a website screenshot API, not a local-file preview or upload service. It cannot replace the Angular code above. If you also need to capture a web page as an image or PDF, its single-request API is separate from your image-picker flow. For a screenshot request, see the ScreenshotNeo API documentation.
Best Value
- 【INTEGRATED SPEAKERS】Whether you're at work or in the midst of an intense gaming session, our built-in speakers provide rich and seamless audio, all while keeping your desk clutter-free.
- 【EASY ON THE EYES】 Protect your eyes and enhance your comfort with Blue-Light Shift technology. This feature reduces harmful blue light emissions from your screen, helping to alleviate eye strain during long hours of use and promoting healthier viewing habits.
- 【WIDEN YOUR PERSPECTIVE】Our sleek minimal bezel design ensures undivided attention. The nearly bezel-free display seamlessly connects in a dual monitor arrangement, delivering an unobstructed view that lets you focus on more at once, completely distraction-free.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
ScreenshotNeo removes cookie and consent banners, newsletter popups, and chat widgets before capture. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents. The Free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots. Those are screenshot-service features, not a way to preview the file selected in this Angular component.
Sign up for ScreenshotNeo’s free plan: 1,000 screenshots a month, no card required.
FAQ
Can Angular preview a file before it has been uploaded?
Yes. The browser can display the file the user selected locally. The preview does not send the file to your server.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Can a page preview a file from an arbitrary local path?
No. The page works with files the user makes available through a file input or drag and drop; it cannot freely read arbitrary paths from the user’s device.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

