QBO Dataservice image upload

51 Views Asked by At

I would like to upload an image attachment to Quickbooks Online and attach it to an Item using my windows forms application. I am using the DataService class and my connection works fine. I create the Attachable object and load the image data into a MemoryStream. The problem comes when I run the DataService.Upload() method, the new attachment is create in QBO just like expected, but there is no image and the size is 0: enter image description here

I installed Fiddler to get the request, which is as follows:

--51678f9d-94b1-4bbc-83fb-7620b6c9c363
Content-Disposition: form-data; name="file_metadata_0"
Content-Type: application/xml

<?xml version="1.0"?>
<Attachable xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schema.intuit.com/finance/v3">
  <AttachableRef>
    <EntityRef type="Item">29</EntityRef>
  </AttachableRef>
  <FileName>Image.jpg</FileName>
  <ContentType>image/jpeg</ContentType>
</Attachable>
--51678f9d-94b1-4bbc-83fb-7620b6c9c363
Content-Disposition: form-data; name="file_content_0"; filename="Image.jpg"
Content-Type: image/jpeg
Content-Transfer-Encoding: binary


--51678f9d-94b1-4bbc-83fb-7620b6c9c363

At the bottom, the Content-Transfer-Encoding is set to binary and there is no encoded data. Does someone have an explanation for this?

If I use Convert.ToBase64String(ms.ToArray) and copy the resulting string into Postman with Content-Transfer-Encoding set to "base64", everything works just like expected.

0

There are 0 best solutions below