uploadthing icon indicating copy to clipboard operation
uploadthing copied to clipboard

[bug]:UploadDropZone component in Svelte prompts for multiple files even if endpoint has only one file allowed (then silently fails)

Open Pascaltib opened this issue 1 year ago • 13 comments

Provide environment information

System:
    OS: macOS 14.5
    CPU: (8) arm64 Apple M1
    Memory: 156.34 MB / 8.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 21.5.0 - ~/.nvm/versions/node/v21.5.0/bin/node
    npm: 10.2.4 - ~/.nvm/versions/node/v21.5.0/bin/npm
  Browsers:
    Chrome: 127.0.6533.120
    Safari: 17.5
  npmPackages:
    typescript: ^5.5.3 => 5.5.3
    uploadthing: ^6.13.2 => 6.13.2

Describe the bug

Even though my fileroute specifies that only one file is allowed, the UploadDropzone allows users to select multiple files which will then trigger an error.

fileUploader: f({
		'application/pdf': { maxFileSize: '32MB', maxFileCount: 1, minFileCount: 1 },
		'application/vnd.openxmlformats-officedocument.wordprocessingml.document': {
			maxFileSize: '32MB'
		},
		'application/vnd.openxmlformats-officedocument.presentationml.presentation': {
			maxFileSize: '32MB'
		},
		'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': {
			maxFileSize: '32MB'
		},
		'application/vnd.oasis.opendocument.text': {
			maxFileSize: '32MB'
		},
		'application/vnd.oasis.opendocument.presentation': {
			maxFileSize: '32MB'
		},
		'application/vnd.oasis.opendocument.spreadsheet': {
			maxFileSize: '32MB'
		}
	})

Here is my component usage:

		const uploader = createUploader('fileUploader', {
		onBeforeUploadBegin: (files) => {
			filesList = files
			return files
		},
		onClientUploadComplete: (res) => {
			showFiles = true
			filesUploadedStore.set(res)
		},
		onUploadError: (error) => {
			console.error('Uploadthing Error', error)
			toast.error('Error uploading file')
			Sentry.captureException(error)
		}
	})
	....
	<UploadDropzone {uploader} />
	

I cannot find any way to prevent the file selector from allowing for multiple uploads. The documentation is pretty limited for svelte and trying to decipher the types is very difficult.

Is there a way to do this?

I have marked this as a bug since <UploadButton {uploader} /> works as expected only allowing for one file to be chosen.

Link to reproduction

None provided!

To reproduce

  1. In a sveltekit project create a route which only allows for one file ex/
strictImageAttachment: f({
    image: { maxFileSize: "2MB", maxFileCount: 1, minFileCount: 1 },
  })
    .middleware(({ req }) => auth(req))
    .onUploadComplete((data) => console.log("file", data))
  1. Use this route with the UploadDropzone component (through uploader)
  2. User will be allowed to select multiple files which will trigger an error.

Additional information

No response

👨‍👧‍👦 Contributing

  • [ ] 🙋‍♂️ Yes, I'd be down to file a PR fixing this bug!

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

Pascaltib avatar Aug 26 '24 16:08 Pascaltib

@Pascaltib Confirmed this behaviour, I think I may have already addressed it as part of #886, but there are still some outstanding issues in that PR that I have not resolved yet. (unfortunately I am not super familiar with svelte, so it has been slow for me to work on)

markflorkowski avatar Aug 26 '24 17:08 markflorkowski

I see! Good luck :)

Pascaltib avatar Aug 26 '24 17:08 Pascaltib

You can try the canary linked in that PR, although the dropzone button is not working for some reason, which may be a worse behavior :/

markflorkowski avatar Aug 26 '24 17:08 markflorkowski

Those changes are now in the latest released version of the uploadthing/svelte package! Feel free to reopen if you are still facing issues!

markflorkowski avatar Sep 07 '24 03:09 markflorkowski

That's awesome! I'll try it out and let you know if I have any issues 🙏

Pascaltib avatar Sep 09 '24 08:09 Pascaltib

Hey @markflorkowski. Unfortunately the behaviour of the UploadDropZone remains bugged.

It is actually a bit worse now since before it would throw an error but now it silently fails and remains stuck.

Could you reopen this issue? I do not have the permissions to do so.

I am using: "@uploadthing/svelte": "^6.7.0", "uploadthing": "^6.13.3"

Pascaltib avatar Sep 10 '24 17:09 Pascaltib

Hey @Pascaltib sorry to hear that. Will try to take a look this week.

markflorkowski avatar Sep 10 '24 18:09 markflorkowski

I am using: "@uploadthing/svelte": "^6.7.0", "uploadthing": "^6.13.3"

@Pascaltib - just as a sanity check, can you remove the carets, delete your node_modules and do a clean install to see if the issue persists?

markflorkowski avatar Sep 10 '24 20:09 markflorkowski

Issue persists after clean install without carets 🥲

Pascaltib avatar Sep 11 '24 09:09 Pascaltib

Thank you for confirming that :/ Haven't had a chance to dig in on this yet, but I promise I have not forgotten.

markflorkowski avatar Sep 11 '24 16:09 markflorkowski

Any updates on this @markflorkowski?

Pascaltib avatar Sep 23 '24 19:09 Pascaltib

+1 getting this error on v7 with sveltekit :

14:53:51.959 INFO  handleUploadAction Sending presigned URLs to client
ᐉ { "presignedUrls": [{"url":"https://sea1.ingest.uploadthing.com/pc9M973G6Mu8mSUVK8wwqJ0Td4H3rx1j9zsPl7KQ2aYLOAZX?expires=1727182431954&x-ut-identifier=3lmh1ldr8g&x-ut-file-name=main-qimg-bc54d4d995526ae5eb9877c1c00ce725-lq.jfif&x-ut-file-size=113049&x-ut-file-type=image%252Fjpeg&x-ut-slug=imageUploader&x-ut-content-disposition=inline&signature=hmac-sha256%3Dc23a4f2245bfee6cafea6c9b430c4d30d85f7d2fcd4bb3fae9670281a4ca78e7","key":"pc9M973G6Mu8mSUVK8wwqJ0Td4H3rx1j9zsPl7KQ2aYLOAZX","name":"main-qimg-bc54d4d995526ae5eb9877c1c00ce725-lq.jfif","customId":null}] }
14:53:54.677 INFO  handleUploadAction -> handleJsonLineStream Successfully simulated 'callback' event
14:53:54.988 ERROR handleCallbackRequest Failed to register callback result (400)
ᐉ { "error": {"error":"Invalid request body","details":[{"code":"invalid_type","expected":"object","received":"string","path":["callbackData"],"message":"Expected object, received string"}]} } 

The image does upload however it doesn't return a response object

cliffordkleinsr avatar Sep 24 '24 13:09 cliffordkleinsr

Work in progres for this, as well as issues in other framework adapters - https://github.com/pingdotgg/uploadthing/pull/980

markflorkowski avatar Oct 03 '24 20:10 markflorkowski

@cliffordkleinsr Your issue looks related to this: https://github.com/pingdotgg/uploadthing/pull/968

Make sure to return an object from onUploadComplete. Next patch you'll get a type error if you don't return an object

juliusmarminge avatar Oct 07 '24 22:10 juliusmarminge

Confirmed the original issue is fixed by #980. Release will be out shortly

juliusmarminge avatar Oct 08 '24 21:10 juliusmarminge

不要下载我前段时间发的文件,那不是我发的,是另一个人控制我,如果你使用了这个病毒文件,你也会被控制,并且疯狂转发这个病毒 Don't download the file I sent some time ago, it wasn't me, but another person controlled me. If you use this virus file, you will also be controlled and forward this virus crazily.

MinecraftEarthVillage avatar Nov 09 '24 03:11 MinecraftEarthVillage