Skip to content

Axios FormData with file #4955

@passakorn-new

Description

@passakorn-new

My environment
[Svelte] --FormData submit--> [SvelteKit Endpoint] --call for save file --> [Rails]

Describe the issue

I uploaded the file and submitted the form to the SvelteKit Endpoint. Then I passed FormData from SvelteKit to Rails by Axios get error "Data after transformation must be a string, an ArrayBuffer, a Buffer, or a Stream"

Example Code

Code snippet to illustrate your question

[svelte]
<form
    on:submit
    method="post"
    enctype="multipart/form-data"
    action="/api/reports"
>
   <Fileupload name="report[thumbnail]" size="sm" accept="image/png, image/jpeg" />
</form>

[sveltekit endpoint]
export const POST: RequestHandler = async ({ request, locals }) => {
    const form = await request.formData();    // get formData
    const response = await axios.post(`${url}`, data) // send form data
};

Expected behavior, if applicable

I think can send FormData value to Rails server

Environment

"axios": "^0.27.2",
"@sveltejs/adapter-node": "1.0.0-next.88",
"@sveltejs/kit": "next",

Additional context/Screenshots

Screen Shot 2565-09-13 at 01 53 19

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions