Closed shehryarbajwa closed 3 months ago
The following snippet is incorrect:
console.log('Starting upload...');
const res = await startUpload(acceptedFiles);
console.log('Upload response:', res);
if (!res || res.length === 0) {
console.log('Upload failed or no response');
throw new Error('Upload failed or no response');
}
As seen in our docs, the startUpload
function is not expected to return anything.
If you would like to have code that runs when an upload fails, you would pass it into useUploadthing
via the onUploadError
key:
const { startUpload, isUploading, permittedFileInfo } = useUploadThing(
endpoint,
opts: {
onClientUploadComplete: ({fileKey: string, fileUrl: string}[]) => void
onUploadError: (error: Error) => void
onUploadAborted: () => void
onUploadProgress: (progress: number) => void
onUploadBegin: (fileName: string) => void
},
);
For more information, check out our documentation on useUploadThing
I am trying to use a key which is returned when the network call completes.
const [fileResponse] = res;
const key = fileResponse?.key;
console.log('File key:', key);
Should I do this with onClientUploadComplete instead!
Either there, or on the server-side onUploadComplete
π
Hey @markflorkowski I tried on the client side and it works fine. Not sure why I can't see the metadata on the server side. Shouldn't they be working on both? Client side(This call does the console log)
(This one doesn't even though the middleware works just fine. Doesn't do the db call either)
This one doesn't even though the middleware works just fine. Doesn't do the db call either
Are you running a production build locally? If so, there is no way for uploadthing callbacks to make it to your server, so the onUploadComplete
will never run. If you are running in NODE_ENV=development
though, you should be seeing simulated callbacks (with corresponding console logs)
Wow this was unbelievable. I feel like this can be added to the docs since Ive seen many posts using this library make this silly mistake. Can I make a pull request to add in the docs?
It's already in the docs: https://docs.uploadthing.com/faq#youre-testing-a-production-build-locally
Provide environment information
Describe the bug
Link to reproduction
https://github.com/shehryarbajwa/quill/blob/master/src/components/UploadButton.tsx
To reproduce
Here is the uploadthing.ts file and the pdfUploader
Here is the error I get in the console when I try to log
Error: Uncaught (in promise) Error: A listener indicated an asynchronous response by returning true, but the message channel closed before a response was received
162-5a8605f2ab2e0772.js:1 Error during upload: Error: Upload failed or no response at onDrop (page-17a9efdf319d8eb1.js:1:3431)
Additional information
Not sure what I am doing wrong here
π¨βπ§βπ¦ Contributing
Code of Conduct