Skip to content

Commit 46717b6

Browse files
committedMay 14, 2022
chore: format
1 parent 25b4c83 commit 46717b6

File tree

6 files changed

+54
-50
lines changed

6 files changed

+54
-50
lines changed
 

‎docs/api/remix.md

+38-29
Original file line numberDiff line numberDiff line change
@@ -1671,22 +1671,30 @@ import type {
16711671
} from "cloudinary";
16721672
import cloudinary from "cloudinary";
16731673

1674-
async function uploadImageToCloudinary(data: AsyncIterable<Uint8Array>) {
1675-
const uploadPromise = new Promise<UploadApiResponse>(async (resolve, reject) => {
1676-
const uploadStream = cloudinary.v2.uploader.upload_stream(
1677-
{
1678-
folder: "remix",
1679-
},
1680-
(error, result) => {
1681-
if (error) {
1682-
reject(error);
1683-
return;
1684-
}
1685-
resolve(result);
1686-
}
1687-
);
1688-
await writeAsyncIterableToWritable(data, uploadStream);
1689-
});
1674+
async function uploadImageToCloudinary(
1675+
data: AsyncIterable<Uint8Array>
1676+
) {
1677+
const uploadPromise = new Promise<UploadApiResponse>(
1678+
async (resolve, reject) => {
1679+
const uploadStream =
1680+
cloudinary.v2.uploader.upload_stream(
1681+
{
1682+
folder: "remix",
1683+
},
1684+
(error, result) => {
1685+
if (error) {
1686+
reject(error);
1687+
return;
1688+
}
1689+
resolve(result);
1690+
}
1691+
);
1692+
await writeAsyncIterableToWritable(
1693+
data,
1694+
uploadStream
1695+
);
1696+
}
1697+
);
16901698

16911699
return uploadPromise;
16921700
}
@@ -1696,19 +1704,20 @@ export const action: ActionFunction = async ({
16961704
}) => {
16971705
const userId = getUserId(request);
16981706

1699-
const uploadHandler =
1700-
unstable_composeUploadHandlers(
1701-
// our custom upload handler
1702-
async ({ name, contentType, data, filename }) => {
1703-
if (name !== "img") {
1704-
return undefined;
1705-
}
1706-
const uploadedImage = await uploadImageToCloudinary(data);
1707-
return uploadedImage.secure_url;
1708-
},
1709-
// fallback to memory for everything else
1710-
unstable_createMemoryUploadHandler()
1711-
);
1707+
const uploadHandler = unstable_composeUploadHandlers(
1708+
// our custom upload handler
1709+
async ({ name, contentType, data, filename }) => {
1710+
if (name !== "img") {
1711+
return undefined;
1712+
}
1713+
const uploadedImage = await uploadImageToCloudinary(
1714+
data
1715+
);
1716+
return uploadedImage.secure_url;
1717+
},
1718+
// fallback to memory for everything else
1719+
unstable_createMemoryUploadHandler()
1720+
);
17121721

17131722
const formData = await unstable_parseMultipartFormData(
17141723
request,

‎docs/decisions/0002-do-not-clone-request.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
# Do not clone request
22

3-
Date: 2022-05-13
3+
Date: 2022-05-13
44

5-
Status: accepted
5+
Status: accepted
66

7-
## Context
7+
## Context
88

9-
To allow multiple loaders / actions to read the body of a request, we have been cloning the request before forwarding it to user-code. This is not the best thing to do as some runtimes will begin buffering the body to allow for multiple consumers. It is also goes against "the platform" that states a request body should only be consumed once.
9+
To allow multiple loaders / actions to read the body of a request, we have been cloning the request before forwarding it to user-code. This is not the best thing to do as some runtimes will begin buffering the body to allow for multiple consumers. It is also goes against "the platform" that states a request body should only be consumed once.
1010

11-
## Decision
11+
## Decision
1212

13-
Do not clone requests before they are passed to user-code (loaders, actions, handleDocumentRequest, handleDataRequest, etc.).
13+
Do not clone requests before they are passed to user-code (loaders, actions, handleDocumentRequest, handleDataRequest, etc.).
1414

15-
## Consequences
15+
## Consequences
1616

1717
If you are reading the request body in both an action and a loader this will now fail. Loaders should be thought of as a "GET" / "HEAD" request handler. These request methods are not allowed to have a body, therefore you should not be reading it in your Remix loader function.
1818

‎docs/decisions/template.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Title
22

3-
Date: YYYY-MM-DD
3+
Date: YYYY-MM-DD
44

5-
Status: proposed | rejected | accepted | deprecated | … | superseded by [0005](0005-example.md)
5+
Status: proposed | rejected | accepted | deprecated | … | superseded by [0005](0005-example.md)
66

7-
## Context
7+
## Context
88

9-
## Decision
9+
## Decision
1010

11-
## Consequences
11+
## Consequences

‎examples/file-and-cloudinary-upload/app/routes/cloudinary-upload.tsx

+2-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
json,
44
unstable_composeUploadHandlers as composeUploadHandlers,
55
unstable_createMemoryUploadHandler as createMemoryUploadHandler,
6-
unstable_parseMultipartFormData as parseMultipartFormData
6+
unstable_parseMultipartFormData as parseMultipartFormData,
77
} from "@remix-run/node";
88
import { Form, useActionData } from "@remix-run/react";
99

@@ -27,10 +27,7 @@ export const action: ActionFunction = async ({ request }) => {
2727
createMemoryUploadHandler()
2828
);
2929

30-
const formData = await parseMultipartFormData(
31-
request,
32-
uploadHandler
33-
);
30+
const formData = await parseMultipartFormData(request, uploadHandler);
3431
const imgSrc = formData.get("img");
3532
const imgDesc = formData.get("desc");
3633
if (!imgSrc) {

‎packages/remix-cloudflare/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export {
1919
unstable_composeUploadHandlers,
2020
unstable_parseMultipartFormData,
2121
unstable_createMemoryUploadHandler,
22-
MaxPartSizeExceededError
22+
MaxPartSizeExceededError,
2323
} from "@remix-run/server-runtime";
2424

2525
export type {

‎tsconfig.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
{
22
"files": [],
3-
"exclude": [
4-
"node_modules"
5-
],
3+
"exclude": ["node_modules"],
64
"references": [
75
{ "path": "packages/create-remix" },
86
{ "path": "packages/remix" },

0 commit comments

Comments
 (0)
Please sign in to comment.