Skip to content

Axios FormData with file #4955

Closed
Closed

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

Activity

  1. passakorn-new commented on Sep 13, 2022

    @passakorn-new
    Author

    I change node-fetch instead Axios that work!, but i want to use Axios.

  2. lenivene commented on Sep 16, 2022

    @lenivene

    I'm having the same problem when sending a file using [email protected] version, but I'm tested on [email protected] version and it worked fine

  3. gbersac commented on Apr 14, 2023

    @gbersac

    I'm having the same issue with "axios": "^1.3.5"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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