Object Url
URL representing an object.
Usage
<script>
import {objectUrl} from "@sveu/shared"
let file = undefined
const on_file_change = (e) => {
const target = e.target
const files = target.files
file = files && files.length > 0 ? files[0] : undefined
}
$: url = objectUrl(file)
</script>
<input type="file" on:change="{on_file_change}" />
{url ? url : ""}
<script>
import {objectUrl} from "@sveu/shared"
let file = undefined
const on_file_change = (e) => {
const target = e.target
const files = target.files
file = files && files.length > 0 ? files[0] : undefined
}
$: url = objectUrl(file)
</script>
<input type="file" on:change="{on_file_change}" />
{url ? url : ""}
svelte
Example
<script lang="ts">
import { objectUrl } from "@sveu/shared"
let file: File
const on_file_change = (e: any) => {
const target = e.target
const files = target.files
file = files && files.length > 0 ? files[0] : undefined
}
$: url = objectUrl(file)
</script>
<input type="file" on:change="{on_file_change}" />
<br />
{#if url}
<a href="{url}" target="_blank" rel="noreferrer">Open</a>
{/if}
<script lang="ts">
import { objectUrl } from "@sveu/shared"
let file: File
const on_file_change = (e: any) => {
const target = e.target
const files = target.files
file = files && files.length > 0 ? files[0] : undefined
}
$: url = objectUrl(file)
</script>
<input type="file" on:change="{on_file_change}" />
<br />
{#if url}
<a href="{url}" target="_blank" rel="noreferrer">Open</a>
{/if}
svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Click fold/expand code
API
Arguments
Name | Description | Type | Required |
---|---|---|---|
value | The value to create an object URL for. | Blob or MediaSource | Yes |