Closed nathan-prijot closed 3 months ago
Additionally, attachmentFiles.getByName
does not double the '
in the file name while attachmentFiles.add
does. It's quite funny because in v2, if I'm not mistaken, you had to encode the filename and double the '
for attachmentFiles.add
and not for attachmentFiles.getByName
. So it's the opposite here in v3.
For those wondering, here is what you need to do if you want getByName
to work with the 'raw' file name:
const escapedFileName = encodeURIComponent(attachmentName.replace(/'/g, "''"));
attachmentFiles.getByName(escapedFileName).recycle();
Reminder that you have to do it for attachmentFiles.getByName
but not for attachmentFiles.add
.
Fixed in v4, won't fix in v3.
Closing with merge of fix for v4
This issue is locked for inactivity or age. If you have a related issue please open a new issue and reference this one. Closed issues are not tracked.
Major Version
3.x
Minor Version Number
3.22.0
Target environment
SharePoint Framework
Additional environment details
Typical SPFx v1.18.2
Expected or Desired Behavior
If I have an attachments literally called
Lorem%20ipsum.docx
the following should work:Observed Behavior
It does not encode the filename and calls
https://myorg.sharepoint.com/sites/MySite/_api/web/lists/getByTitle('My List')/items(1)/attachmentFiles('Lorem%20ipsum.docx')/recycleObject
. The filename is not recognized which generate a 400 error.Since
attachmentFiles.add
nows encode the filename, this seems a bit odd to work with.Note that SharePoint itself seems confused about it because the
ServerRelativeUrl
returned by the SharePoint API will also be invalid (as well as theodata.id
andodata.editLink
).Steps to Reproduce
attachmentFiles.add
with as a filenameLorem%20ipsum.docx
.attachmentFiles.getByName
with the same filename.