Pnpjs: How create new item list, with image(thumbnail) field?

Created on 18 Nov 2020  路  3Comments  路  Source: pnp/pnpjs

Category

  • [ ] Enhancement
  • [ ] Bug
  • [x] Question
  • [ ] Documentation gap/issue

Version: [ sp-pnp-js v3.0.10 ]

sharepoint version [ 2013/SharepointOnline ]

I'm try create a new item in list, but when i try add in field image (thumbnail) a image, show me a exception,

_An unexpected 'StartObject' node was found when reading from the JSON reader. A 'PrimitiveValue' node was expected._

My code,

i'm getting file by function Js creating a new FileReader and after gettting the value:


var File = event.target.files[0];

$pnp.sp.web.lists.getByTitle('Links').items.add({
 Title: "Test",
 Image: File
});

I don't want upload a new attachament, I'm need upload in column type thumbnail, please.

non-library answered question

Most helpful comment

Thank you @koltyakov and @patrick-rodgers for answers.

Koltyakov i'm your fan, you are awasome!! It worked!

All 3 comments

Hi @andersonmorony - couple of things:

1) you are on a very old version of PnPjs that is no longer supported, would recommend upgrading as you're missing out on years of improvements.
2) If you are on 2013 you may be missing a patch that allows for minimal metadata you can adjust the "Accept" header to help. Without the patch you're getting back XML and hence the parse error.

Apart from the fact that sp-pnp-js is an old-old deprecated version.

Updating modern image field require uploading the image somewhere on the site and the using the following payload:

const list = sp.web.lists.getByTitle('My List');

await list.items.getById(1).update({
  ImageField: JSON.stringify({
    type: 'thumbnail',
    serverRelativeUrl: '/sites/site/Shared%20Documents/my-image.png'
  })
});

Thank you @koltyakov and @patrick-rodgers for answers.

Koltyakov i'm your fan, you are awasome!! It worked!

Was this page helpful?
0 / 5 - 0 ratings