Upload a just shooted photo from phone to Pocketbase backend with Svelte

393 Views Asked by At

I am trying to add a new record with photo on my Pocketbase backend but it's able to correctly upload just already taken pictures.

I'm sorry but because is a issue that happens only on mobile is difficult to get the console error

That's the code snippet:

<script lang="ts">
    import { pb } from '../lib/pocketbase';

    export let id: string;

    let new_object_name: string;
    let new_object_img: FileList;

    async function addObject(){
        let formData = new FormData();
        formData.append("name", new_object_name);
        formData.append("location_id", id);
        formData.append("photo", new_object_img[0]);
        await pb.collection('objects').create(formData);

        new_object_name = "";
        new_object_img = null;
        document.getElementById('new_obj_file').value = "";
    }
</script>

<form on:submit|preventDefault>
    <input type="text" placeholder="Object Name" bind:value={new_object_name}/>
    <input type="file" id="new_obj_file" accept="image/jpg, image/jpeg, image/png, image/svg+xml, image/gif" bind:files={new_object_img}/>
    <button id="add_object" on:click={addObject}>add object</button>
</form>

I tried on android and on an iPhone and both have the same issues

0

There are 0 best solutions below