-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Properly handle multipart file uploads in the dev server (#4742)
* Properly allow file uploads in the dev server * Smaller image * movethe test over
- Loading branch information
Showing
8 changed files
with
64 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Allow file uploads in dev server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,8 @@ | |
"private": true, | ||
"dependencies": { | ||
"astro": "workspace:*" | ||
}, | ||
"scripts": { | ||
"dev": "astro dev" | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions
32
packages/astro/test/fixtures/ssr-api-route/src/pages/binary.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import fs from 'node:fs'; | ||
|
||
export function get() { | ||
return { | ||
body: 'ok' | ||
}; | ||
} | ||
|
||
export async function post({ request }) { | ||
const data = await request.formData(); | ||
const file = data.get('file'); | ||
|
||
if (file) { | ||
const buffer = await file.arrayBuffer(); | ||
const realBuffer = await fs.promises.readFile(new URL('../images/penguin.jpg', import.meta.url)); | ||
|
||
if(buffersEqual(buffer, realBuffer)) { | ||
return new Response('ok', { status: 200 }); | ||
} | ||
} | ||
return new Response(null, { status: 400 }); | ||
} | ||
|
||
function buffersEqual(buf1, buf2) { | ||
if (buf1.byteLength != buf2.byteLength) return false; | ||
const dv1 = new Uint8Array(buf1); | ||
const dv2 = new Uint8Array(buf2); | ||
for (let i = 0; i !== buf1.byteLength; i++) { | ||
if (dv1[i] != dv2[i]) return false; | ||
} | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters