remix-run / remix

Build Better Websites. Create modern, resilient user experiences with web fundamentals.
https://remix.run
MIT License
29.66k stars 2.5k forks source link

createFileUploadHandler return in action "lastModified: 0" #3002

Open hakimLyon opened 2 years ago

hakimLyon commented 2 years ago

What version of Remix are you using?

1.4.1

Steps to Reproduce


export const action: ActionFunction = async ({ request }) => {
  const uploadHandler = unstable_createFileUploadHandler({
    file: ({ filename }) => filename,
  })
  const formData = await unstable_parseMultipartFormData(request, uploadHandler)

  return { image:formData.get('photo') }
}
.......
<Form replace method="post" encType="multipart/form-data">
 <input
     id="icon-button-file"
     type="file"
     name="photo" />
</Form>

Expected Behavior

lastModified: 1648055313463
lastModifiedDate: Wed Mar 23 2022 17:08:33 GMT+0000 (heure moyenne de Greenwich) {}
name: "Capture d’écran 2022-03-23 à 17.08.27.png"
size: 459225
type: "image/png"
webkitRelativePath: ""

Actual Behavior

filepath: "/var/folders/mk/h2y5kv891ts11l7h9hk3j_gr0000gn/T/Capture d’écran 2022-03-23 à 17.08.27-1651078225913.png"
lastModified: 0
name: "Capture d’écran 2022-03-23 à 17.08.27-1651078225913.png"
size: 459225
type: "image/png"
webkitRelativePath: ""
mcansh commented 2 years ago

looks like we're setting it on creation and never set it to anything else - i've file an internal ticket

https://github.com/remix-run/remix/blob/ffc6000cde2bcdd99c9db53f0b116dabfb2da65e/packages/remix-node/upload/fileUploadHandler.ts#L157

kenn commented 5 months ago

Bump.

lastModified is one last missing piece of instance properties of a File() object.

I'm sending it alongside the file as a hidden input state, but if anyone has a better workaround, I'm interested.

<input
  type="hidden"
  name="lastModified"
  value={lastModified ? new Date(lastModified).toISOString() : ''}
/>