csv uploads

Trying to upload a csv file with UploadThing and keep running into this error, should it be a different file type?
export const ourFileRouter = {
// Define as many FileRoutes as you like, each with a unique routeSlug
csvUploader: f(["text/plain", "text/csv"], ["csv"])
// Set permissions and file types for this FileRoute
.middleware(async ({ req, res }) => {
// This code runs on your server before upload
const user = await auth(req, res);

// If you throw, the user will not be able to upload
if (!user) throw new Error("Unauthorized");

// Whatever is returned here is accessible in onUploadComplete as `metadata`
return { userId: user.id };
})
.onUploadComplete(async ({ metadata, file }) => {
// This code RUNS ON YOUR SERVER after upload
console.log("Upload complete for userId:", metadata.userId);

console.log("file url", file.url);
}),
} satisfies FileRouter;
export const ourFileRouter = {
// Define as many FileRoutes as you like, each with a unique routeSlug
csvUploader: f(["text/plain", "text/csv"], ["csv"])
// Set permissions and file types for this FileRoute
.middleware(async ({ req, res }) => {
// This code runs on your server before upload
const user = await auth(req, res);

// If you throw, the user will not be able to upload
if (!user) throw new Error("Unauthorized");

// Whatever is returned here is accessible in onUploadComplete as `metadata`
return { userId: user.id };
})
.onUploadComplete(async ({ metadata, file }) => {
// This code RUNS ON YOUR SERVER after upload
console.log("Upload complete for userId:", metadata.userId);

console.log("file url", file.url);
}),
} satisfies FileRouter;
Downloads file --mime-type Speedtest\ Results\ Export-2023_07_31.csv
Speedtest Results Export-2023_07_31.csv: text/plain
Downloads file --mime-type Speedtest\ Results\ Export-2023_07_31.csv
Speedtest Results Export-2023_07_31.csv: text/plain
<Error><Code>AccessDenied</Code><Message>Invalid according to Policy: Policy Condition failed: ["eq", "$Content-Type", "text/csv"]</Message><RequestId>JEZTTVM0B2KSBX4R</RequestId><HostId>PgY/8AqUcarif231bRI5/ppS46NG4/NLhxAGPF0EwzC0Kff2yTJF4/xWwgKTxMg8JPHaDc36avE=</HostId></Error>
1 Reply
Neto
Neto2y ago
uploadthing expects a "text/csv" but you are sending a "text/plain"
Downloads file --mime-type Speedtest\ Results\ Export-2023_07_31.csv
Speedtest Results Export-2023_07_31.csv: text/plain // << plain

<Error><Code>AccessDenied</Code><Message>Invalid according to Policy: Policy Condition failed: ["eq", "$Content-Type", "text/csv" /*<< csv */ ]</Message> <RequestId>JEZTTVM0B2KSBX4R</RequestId><HostId>PgY/8AqUcarif231bRI5/ppS46NG4/NLhxAGPF0EwzC0Kff2yTJF4/xWwgKTxMg8JPHaDc36avE=</HostId></Error>
Downloads file --mime-type Speedtest\ Results\ Export-2023_07_31.csv
Speedtest Results Export-2023_07_31.csv: text/plain // << plain

<Error><Code>AccessDenied</Code><Message>Invalid according to Policy: Policy Condition failed: ["eq", "$Content-Type", "text/csv" /*<< csv */ ]</Message> <RequestId>JEZTTVM0B2KSBX4R</RequestId><HostId>PgY/8AqUcarif231bRI5/ppS46NG4/NLhxAGPF0EwzC0Kff2yTJF4/xWwgKTxMg8JPHaDc36avE=</HostId></Error>
Want results from more Discord servers?
Add your server