# Problem on add Attachments (PHP Project)

**URL:** https://discuss.tryton.org/t/problem-on-add-attachments-php-project/866
**Category:** Developer
**Created:** [November 9, 2018, 2:34pm UTC](https://discuss.tryton.org/t/problem-on-add-attachments-php-project/866 "2018-11-09T14:34:18Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Vincenzo](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/vincenzo/32/847_2.png) [@Vincenzo](https://discuss.tryton.org/u/Vincenzo)
#### Post date: [November 9, 2018, 2:34pm UTC](https://discuss.tryton.org/t/problem-on-add-attachments-php-project/866/1 "2018-11-09T14:34:18Z")

</div>

Good afternoon,  
I’m continuing with my PHP project with JSON-RPC calls to the Tryton server.  
I have a problem: I can not insert attachments.

I’m using the model.ir.attachment.create method.

Which format should I convert the file to?  
What does the bytearray method do?

Thank you

---

<div class="post-metadata">

### Author: ![albert](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/albert/32/21_2.png) [@albert](https://discuss.tryton.org/u/albert)
#### Post date: [November 9, 2018, 3:25pm UTC](https://discuss.tryton.org/t/problem-on-add-attachments-php-project/866/2 "2018-11-09T15:25:18Z")

</div>

I guess you should use base64 for the binary content

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [November 9, 2018, 3:30pm UTC](https://discuss.tryton.org/t/problem-on-add-attachments-php-project/866/3 "2018-11-09T15:30:15Z")

</div>

Indeed the JSON format for binary value is an object like `{' __class__': 'bytes', 'base64': value} ` where value is the content encoded in base64.

---

<div class="post-metadata">

### Author: ![Vincenzo](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/vincenzo/32/847_2.png) [@Vincenzo](https://discuss.tryton.org/u/Vincenzo)
#### Post date: [November 12, 2018, 10:20am UTC](https://discuss.tryton.org/t/problem-on-add-attachments-php-project/866/4 "2018-11-12T10:20:57Z")

</div>

I can not make it work…  
Analyzing the data exchanged by the client in verbose mode I send this:

`INFO:tryton.rpc:model.ir.attachment.create([{u'data': bytearray(b'VALUE'), u'resource': 'stock.shipment.out.return,1', u'name': u'FB_IMG_1503910564025.jpg', u'type': u'data'}], PREF)`

I should enter

`{' __class__': 'bytes', 'base64': value}`

instead of

`bytearray(b'VALUE')`?

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [November 12, 2018, 10:51am UTC](https://discuss.tryton.org/t/problem-on-add-attachments-php-project/866/5 "2018-11-12T10:51:55Z")

</div>

> [@Vincenzo](#):
>
> I should enter
> 
> `{' __class__': 'bytes', 'base64': value}`
> 
> instead of
> 
> `bytearray(b'VALUE')` ?

Yes bytearray is the Python object which does not exist in PHP.

---

<div class="post-metadata">

### Author: ![system](https://discuss-cdn.tryton.org/uploads/default/original/1X/c6f8ec0a40525cdcd50058c734283450a4b3d38b.png) [@system](https://discuss.tryton.org/u/system)
#### Post date: [December 12, 2018, 10:52am UTC](https://discuss.tryton.org/t/problem-on-add-attachments-php-project/866/6 "2018-12-12T10:52:05Z")

</div>

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