# Error when I wanted to try to create a CBOR object from the content of a PDF file and insert it into an ingest-attachment

**URL:** <https://discuss.elastic.co/t/error-when-i-wanted-to-try-to-create-a-cbor-object-from-the-content-of-a-pdf-file-and-insert-it-into-an-ingest-attachment/303535>\
**Category:** Elasticsearch\
**Created:** [April 28, 2022, 3:25pm UTC](https://discuss.elastic.co/t/error-when-i-wanted-to-try-to-create-a-cbor-object-from-the-content-of-a-pdf-file-and-insert-it-into-an-ingest-attachment/303535 "2022-04-28T15:25:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Asmaa\_Oufkir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/asmaa_oufkir/32/31746_2.png) [@Asmaa\_Oufkir](https://discuss.elastic.co/u/Asmaa_Oufkir)\
**Post date:** [April 28, 2022, 3:25pm UTC](https://discuss.elastic.co/t/error-when-i-wanted-to-try-to-create-a-cbor-object-from-the-content-of-a-pdf-file-and-insert-it-into-an-ingest-attachment/303535/1 "2022-04-28T15:25:56Z")

</div>

```auto
File IN_FILE = ResourceUtils.getFile("classpath:test.pdf");
   	int length = (int) IN_FILE.length();
   	RandomAccessFile aFile = new RandomAccessFile(IN_FILE, "r");
   	System.out.println("aFile :"+aFile);
       FileChannel inChannel = aFile.getChannel();
       MappedByteBuffer buffer = inChannel.map(FileChannel.MapMode.READ_ONLY, 0, inChannel.size());
       System.out.println("inChannel.size() :"+inChannel.size());
       buffer.load(); 
       //byte[] result = new byte[length];
       for (int i = 0; i < buffer.limit(); i++)
       {
          System.out.print((char) buffer.get());
       	//result[i] = buffer.get(i++);
       }
       
   	CBORObject object;

       
      object = CBORObject.FromObject(buffer.toString());
       json.put("smart_content", object);

```

I got this error when I wanted to try to create a CBOR object from the content of a PDF file and insert it into an ingest-attachment(smart\_content) field via a JSONObject(json.put):

co.elastic.clients.Elasticsearch.\_types.ElasticsearchException: [es/index] failed: [illegal\_argument\_exception] Content field [smart\_content] of unknown type [java.util.HashMap], must be string or byte array

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 26, 2022, 3:26pm UTC](https://discuss.elastic.co/t/error-when-i-wanted-to-try-to-create-a-cbor-object-from-the-content-of-a-pdf-file-and-insert-it-into-an-ingest-attachment/303535/2 "2022-05-26T15:26:10Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
