25 days ago
sanity check.
should i be able to write a bun function on railway using a bucket so that i can have a simple webpage where people can drop files into it and it goes in the bucket.
ive been trying with railway AI for the past 2 hours and no dice. lol. maybe theres some inherent limitation with a railway function and a bucket?
4 Replies
25 days ago
Yes, it's totally possible, although the Railway AI might not be powerful enough for this task, so you might need to guide it a bit. Maybe if you provide this to the AI it might be able to pull it off:
Basically, you will need to create an S3Client using Bun's built-in client:
const client = new S3Client({
accessKeyId: process.env.AWS_ACCESS_KEY_ID ?? "",
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY ?? "",
bucket: process.env.AWS_BUCKET_NAME ?? "",
endpoint: process.env.AWS_ENDPOINT_URL ?? "",
});For the environment variables, you can go to your bucket and click the Add to Service button.
Make sure that all upload/download functionality is implemented server-side. No environment variables should be exposed to the client. If the use case allows it, use pre-signed URLs for uploading and downloading instead of proxying the data.
Here's a simple example of how the routes would look:
const server = Bun.serve({
routes: {
"/health": new Response("OK"),
"/api/presigned-url": async () => {
// Generate a pre-signed URL for client-side uploads
const uploadUrl = client.presign("uploads/image.jpg", {
method: "PUT",
expiresIn: 3600,
type: "image/jpeg",
acl: "public-read"
});
return Response.json({ url: uploadUrl });
},
// Fallback for unmatched routes
"*": () => new Response("Not Found", { status: 404 }),
}
});
console.log(`Server running at ${server.url}`);though, I really would recommend using Opus or Codex if you have access to it.
thank you. indeed i have access to claude but didn't think I could get the function + bucket to work. Let me give this a whirl as I ended up getting claude to write this as a full blown react app lmao. meanwhile a simple bun would be way easier to maintain.
indeed i took your response and threw it in the AI and now it worked. thank you!
25 days ago
Great, do you have any remaining issue/problem?
Status changed to Solved passos • 24 days ago