pingdotgg / uploadthing

File uploads for modern web devs
https://uploadthing.com
MIT License
4.19k stars 312 forks source link

feat: add fileKey param to uploadFiles method #400

Closed miguelvelasquezdev closed 1 year ago

miguelvelasquezdev commented 1 year ago

Describe the feature you'd like to request

Hey! I hope this issue/feature will help to the Uploadthing's DX and UX!

I was thinking that would be great to add the fileKey param to uploadFiles method in order to avoid call 2 methods to do so (uploadFiles and renameFile). In addition, calling two endpoints delays the upload of the files two times of what I was expecting!!

I wanted to raise a PR but it seems that needs an endpoint to achieve this new feature.

Describe the solution you'd like to see

export type FileEsque =
  | (Blob & { name: string })
  | (UndiciFile & { fileKey?: string });

uploadFiles(file: FileEsque);

Additional information

No response

πŸ‘¨β€πŸ‘§β€πŸ‘¦ Contributing

juliusmarminge commented 1 year ago

Not sure I understand, do you want to provide your own fileKey instead of letting uploadthing generate one for you?

miguelvelasquezdev commented 1 year ago

Yes, it's just to add a new param that lets me provide my own fileKey, this param could be optional, and if this param it's not provided then uploadthing will generate one for me instead. I saw that the S3 API lets you do so, and I think that it helps a looot

markflorkowski commented 1 year ago

I am curious why you need to call rename file immediately after uploading? Why not just rename the file before uploading it?

miguelvelasquezdev commented 1 year ago

Maybe you're confusing the file's name and the fileKey, the property that's actually important is fileKey, with that you can delete your file or add your own id to do some internal business stuff

markflorkowski commented 1 year ago

I was thinking that would be great to add the fileKey param to uploadFiles method in order to avoid call 2 methods to do so (uploadFiles and renameFile)

From this it seemed like you wanted to be able to set the file key so that you can call renameFile() without waiting for uploadFiles() to give you back the fileKey -- perhaps I am misunderstanding though.

I am trying to understand why you would need to set the file key

miguelvelasquezdev commented 1 year ago

yes, you're right!

Well, is as simple as the same reasons of why uploadthing has a renameFile method, but instead it will be faster than waiting to upload the files and then renaming them. It doesn’t make sense to me.

I need to rename the key cause of internal stuff in my project, let's say security or organization (by date, by folder or by pattern). In my case I am presetting a fileKey, then if I am receiving a different fileKey I must save two different keys (ut_key and key) in my db. Other option is wait the double of time cause I need to wait for the files to be uploaded to rename them.

markflorkowski commented 1 year ago

The reason why we generate the keys is so that we can guarantee that they will be URL safe and will not have any conflicts.

We expect that if you need to do some other form of organization, you will map the keys that we provide to you to something more meaningful for your application in your own DB (eg by using two different keys (ut_key and key) as you suggested). Our file keys are intended to simply be a unique identifier that you can use to retrieve the file. The file renaming capability we offer (with the renameFile api) is intended to alter the filename that users will see when they download the file.

miguelvelasquezdev commented 1 year ago

well, thinking makes sense to me now! maybe this feature is not necessary at all