ajesuscode
ajesuscode14mo ago

get a url with path to a file in an action

I am wondering how can i get a file path, so I can provide it to OpenAiWhishperer. Cuz passing an url throws me an error: Uncaught (in promise) Error: [CONVEX A(actions:langchain)] Uncaught Error: ENOENT: no such file or directory. But when i click on url the image is downloding. So I assume there should be a valid path to the image, that I can provide to Whisher.?
8 Replies
Michal Srb
Michal Srb14mo ago
Hey @ajesuscode, can you provide a snippet of your code? It’s unclear what you’re trying to achieve.
ajesuscode
ajesuscodeOP14mo ago
export const langchain = action({
args: { file: v.any() },
handler: async (_, args) => {

const loader = new OpenAIWhisperAudio(args.file);
console.log("loader", loader);
const docs = await loader.load();
const text = docs[0].pageContent;
return "done";

}
})
export const langchain = action({
args: { file: v.any() },
handler: async (_, args) => {

const loader = new OpenAIWhisperAudio(args.file);
console.log("loader", loader);
const docs = await loader.load();
const text = docs[0].pageContent;
return "done";

}
})
Biut it says that Convex doesnt support Blob type (( OpenAIWhisperAudio accepts only Blob or exact path to file
Michal Srb
Michal Srb14mo ago
You'll need to use an action (https://docs.convex.dev/functions/actions), and load the file before passing it to OpenAIWhisperAudio. You could: - Fetch the file from somewhere using fetch and directly pass it to OpenAIWhisperAudio - Accepting the blob in an HTTP Action (https://docs.convex.dev/functions/http-actions) (like here, you don't have to store it: https://docs.convex.dev/file-storage/upload-files#defining-the-upload-http-action ) - Use Convex file storage https://docs.convex.dev/file-storage/store-files File blobs are indeed not supported as arguments to queries/mutations/actions.
HTTP Actions | Convex Developer Hub
HTTP actions allow you to build an HTTP API right in Convex!
Storing Generated Files | Convex Developer Hub
Files can be uploaded to Convex from a client and stored directly, see
Uploading and Storing Files | Convex Developer Hub
Files can be uploaded by your users and stored in Convex.
ajesuscode
ajesuscodeOP14mo ago
Thanx for such detailed approach. It helpful in some cases, but I am more interested in actual file path, with file extenssion, like https://blablablaurl.com/filename_whatever.mp3 or mov or whatever extenssion is. Is it possible to have from Convex Storage?
Michal Srb
Michal Srb14mo ago
You can write an HTTP Action that serves at such an URL: https://docs.convex.dev/file-storage/serve-files#serving-files-from-http-actions You'll have to store the file name yourself in a Convex table, Convex Storage doesn't include it.
Serving Files | Convex Developer Hub
Files stored in Convex can be served to your users by generating a URL pointing
ian
ian14mo ago
Or you can get the url from something stored in file storage: await ctx.storage.getUrl(storageId)
Michal Srb
Michal Srb14mo ago
(that URL will not have a file name with extension, but it will be a URL)
ajesuscode
ajesuscodeOP14mo ago
Thank you guys. For the moment I went with api call solution, where I temporary store a file like this:
const data = await req.formData();
const file: File = data.get("file") as unknown as File;
if (!file) {
return NextResponse.json({ success: false });
}
console.log("file", file);
const bytes = await file.arrayBuffer();
const buffer = Buffer.from(bytes);

const path = join("/", "tmp", file.name);
await writeFile(path, buffer);
console.log("path", path);
const data = await req.formData();
const file: File = data.get("file") as unknown as File;
if (!file) {
return NextResponse.json({ success: false });
}
console.log("file", file);
const bytes = await file.arrayBuffer();
const buffer = Buffer.from(bytes);

const path = join("/", "tmp", file.name);
await writeFile(path, buffer);
console.log("path", path);
And I have that path to send to Whishper. Will look into, how to do it fully with Convex

Did you find this page helpful?