bkyerv
11/26/2022, 2:22 PMkian
11/26/2022, 2:24 PMbkyerv
11/26/2022, 2:29 PMzsmooth
11/26/2022, 2:30 PMconst buffer = await fileUploaded.arrayBuffer();
const bucketPut = await env.PIC.put(uuid, buffer, bucketPutOptions);
However: you probably want to stream the contents to r2 and this will buffer it in the worker, and I have no idea why it works locally.
Edit: Here's what you want: const bucketPut = await env.PIC.put(
uuid,
fileUploaded.stream(),
bucketPutOptions
);
bkyerv
11/26/2022, 2:33 PMzsmooth
11/26/2022, 2:33 PMreadableStream
from the uploaded File and passes it along, so you're not buffering the file contents.bkyerv
11/26/2022, 2:33 PMzsmooth
11/26/2022, 2:34 PM--experimental-local
maybe your original code will stop working locallyJustinNoel
11/26/2022, 2:53 PMtype UsesMiddlewareProps = {
url: string;
};
// Requests with these strings should not have middleware added to them.
export const undesiredPaths = [
".css",
".ico",
".js",
".png",
".jpeg",
".jpg",
".svg",
".wepb",
"/fonts/"
];
export function getUsesMiddleware({url} : UsesMiddlewareProps): boolean {
return ! undesiredPaths.some((undesiredString) => {
return url.includes(undesiredString);
});
}
I call getUsesMiddleware
with a URL to decide if I need to do extra stuff with the request.zsmooth
11/26/2022, 4:04 PMzsmooth
11/26/2022, 4:04 PMSkye
11/26/2022, 4:05 PMJeremyJaydan
11/27/2022, 10:01 PMcontext.env
? I'm thinking of instantiating a faunadb client in a module then importing that, but then I'd have to dependency inject the secrets from where-ever I'm calling it from and I'm not sure about that.
Alternatively I'm thinking of instantiating the client in middleware which would work but there's more logic I'd like to write associated with the faunadb client / other services. Also how would I pass that down in the middleware, context.env
is that the practice?
is there another preferred way of instantiating services to use across a cloudflare pages codebase? :)James
11/27/2022, 10:05 PMcontext.env
and passing it around. If it's something you plan to re-use in many places, you may want to extract it to your own Pages Plugin: https://developers.cloudflare.com/pages/platform/functions/plugins/
But that doesn't change much - it's essentially just reusable middleware.JeremyJaydan
11/27/2022, 10:05 PMSkye
11/27/2022, 10:06 PMcontext.data
Skye
11/27/2022, 10:06 PMJeremyJaydan
11/27/2022, 10:15 PMenv
and data
? also I'm concerned about compatibility in the future for example if I set a env.HOUSE
for example then cloudflare releases a binding called env.HOUSE
, would that be an issue?Skye
11/27/2022, 10:16 PMSkye
11/27/2022, 10:16 PMHOUSE
binding yourself - it wouldn't suddenly just appear and overwrite your functions)JeremyJaydan
11/27/2022, 10:17 PMenv.ASSETS
is a default binding right? I'm guessing cloudflare doesn't want to pollute it eitherSkye
11/27/2022, 10:18 PMSkye
11/27/2022, 10:18 PMJeremyJaydan
11/27/2022, 10:19 PMJeremyJaydan
11/27/2022, 10:19 PMadaptive
11/28/2022, 1:44 PMnightshade427
11/28/2022, 4:28 PMJames
11/28/2022, 4:40 PMnightshade427
11/28/2022, 4:56 PMJames
11/28/2022, 5:00 PM