0

I'm able to access the properties inside the File object (Eg. name, size, etc) but I'm not able to mutate it. I wanted to know, how would I do that.

If that is not possible, then how can I convert the File object to a Javascript object

console log screenshot

Purpose: Wanted to truncate the name of the file if it exceeds a certain limit.

Eg: 

Input : 

File { 
   lastModified: 1633413497251
   name: "Screenshot_2022-09-18-13-25-22-10_6012fa4d4ddec268fc5c7112cbb265e7_Screenshot_2022-09-18-13-25-22-10_6012fa4d4ddec268fc5c7112cbb265e7.jpeg"
  ​ size: 384664
   ​type: "image/jpeg"
​   webkitRelativePath: ""
}

Output : 

File { 
   lastModified: 1633413497251
   name: "Screenshot_2022-09-18-13-_TRUNCATED_fa4d4ddec268fc5c7112cbb265e7.jpeg"
  ​ size: 384664
   ​type: "image/jpeg"
​   webkitRelativePath: ""
}

Hritik Jaiswal
  • 311
  • 3
  • 4
  • It seems your File object it soon a Javascript object !! Could precise your question ? please – Popovkov57 Oct 11 '22 at 12:13
  • 3
    https://stackoverflow.com/questions/30733904/renaming-a-file-object-in-javascript – epascarello Oct 11 '22 at 12:14
  • @Popovkov57 Actually, our Backend rejects the attachment, if the filename character length goes beyond 70 Characters. So if the end-user tried to upload an attachment greater than > 70 char, the attachment won't get uploaded. I think that the end-user shouldn’t be responsible for this limitation. they are free to upload the attachment without any issue. I thought to control the limitation in the frontend by truncating the filename before firing the request to the Backend. – Hritik Jaiswal Oct 11 '22 at 13:26

0 Answers0