-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add upload functionality in the middleware (#7323)
* feat: add upload functionality in the middleware
- Loading branch information
1 parent
3fcf43c
commit f02f7cf
Showing
23 changed files
with
694 additions
and
55 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,23 @@ | ||
--- | ||
"@vue-storefront/middleware": minor | ||
--- | ||
|
||
**[ADDED]** Support for file uploads | ||
Now you can upload files to the server with a `multipart/form-data` content type. Files are available in the `req.files` object. | ||
|
||
```ts | ||
// Example of an endpoint that handles file uploads | ||
export const upload = (context) => { | ||
// Files are available in the `req.files` object | ||
const { files } = context.req; | ||
|
||
// Do something with files | ||
|
||
return Promise.resolve({ | ||
status: 200, | ||
message: "ok", | ||
}); | ||
}; | ||
``` | ||
|
||
Please, read the [Getting Started guide](https://docs.alokai.com/middleware/guides/getting-started#file-upload-configuration) for more information about file uploads. |
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
10 changes: 10 additions & 0 deletions
10
packages/middleware/__tests__/integration/bootstrap/api/upload/index.ts
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,10 @@ | ||
export const upload = (context) => { | ||
const { files } = context.req; | ||
|
||
return Promise.resolve({ | ||
status: 200, | ||
message: "ok", | ||
error: false, | ||
files, | ||
}); | ||
}; |
16 changes: 16 additions & 0 deletions
16
packages/middleware/__tests__/integration/bootstrap/serverWithUpload.ts
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,16 @@ | ||
import { apiClientFactory } from "../../../src/apiClientFactory"; | ||
import * as api from "./api"; | ||
|
||
const onCreate = async (config: Record<string, unknown> = {}) => { | ||
return { | ||
config, | ||
client: null, | ||
}; | ||
}; | ||
|
||
const { createApiClient } = apiClientFactory({ | ||
onCreate, | ||
api, | ||
}); | ||
|
||
export { createApiClient }; |
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
Oops, something went wrong.