Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Axios FormData with file #4955

Closed
passakorn-new opened this issue Sep 12, 2022 · 3 comments · Fixed by #5316
Closed

Axios FormData with file #4955

passakorn-new opened this issue Sep 12, 2022 · 3 comments · Fixed by #5316

Comments

@passakorn-new
Copy link

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

@passakorn-new
Copy link
Author

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

@lenivene
Copy link

I'm having the same problem when sending a file using axios@0.27.0 version, but I'm tested on axios@0.21.4 version and it worked fine

@gbersac
Copy link

gbersac commented Apr 14, 2023

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
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants