Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uploading an image with a filename specified always results in the last character of the filename being removed in the browser. #98

Closed
abusch419 opened this issue Feb 1, 2023 · 1 comment · Fixed by sanity-io/sanity-plugin-media#120

Comments

@abusch419
Copy link

abusch419 commented Feb 1, 2023

Describe the bug

Trying to upload an image asset with a filename specified always results in the last character of the filename being removed in the browser.

To Reproduce

Upload an image using Sanity.client.upload()

const fileUpload = await client.assets.upload('image', pngBuffer, {
  contentType: 'image/png',
  filename: 'myFile',
})

console.log('The file was uploaded!', fileUpload)

Expected behavior

I expect to see the filename 'myFile' in the browser under the media details, but I see 'myFil'.
Oddly enough in the media collection view I do see the correct filename.
I also see the correct filename in the request under the originalFilename key.
Please see screenshots.

Screenshots
Filename with last character removed
Screen Shot 2023-02-01 at 1 00 46 PM

Filename showing as specified
Screen Shot 2023-02-01 at 1 03 54 PM

Correct name in the request under the originalFile key
Screen Shot 2023-02-01 at 1 06 17 PM

Which versions of Sanity are you using?

"@sanity/client": "^3.4.1"

What operating system are you using?

Mac OS Monterey 12.1

Which versions of Node.js / npm are you running?

8.19.3
v16.19.0

rexxars added a commit to sanity-io/sanity-plugin-media that referenced this issue Feb 1, 2023
Fixes sanity-io/client#98

If a file is uploaded with an original filename that does not include an extension (`.png` or similar), the `getFilenameWithoutExtension` method will remove the last character of the filename, because it uses the last index of `.`, which is not found, resulting in `-1`.
@rexxars
Copy link
Member

rexxars commented Feb 1, 2023

This seems to be a problem in the media browser, not the actual upload. I've raised a PR to address it here: sanity-io/sanity-plugin-media#120

robinpyon added a commit to sanity-io/sanity-plugin-media that referenced this issue Feb 3, 2023
* fix: prevent removal of last character on no filename extension

Fixes sanity-io/client#98

If a file is uploaded with an original filename that does not include an extension (`.png` or similar), the `getFilenameWithoutExtension` method will remove the last character of the filename, because it uses the last index of `.`, which is not found, resulting in `-1`.

* fix: simplify filename inputs, trim before validation

---------

Co-authored-by: Robin Pyon <[email protected]>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants