0

I am trying to get stream of an attachment, I am using Copy.asmx I can get a stream of a document stored in a document library but for the attachment I get 0 result.

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetItemResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/">
  <GetItemResult>0</GetItemResult>
</GetItemResponse>
</soap:Body>
</soap:Envelope>
0

You could try this, SPServices is wraped with soap service.

<script type="text/javascript" src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/2014.02/jquery.SPServices.js"></script>
    <script type="text/javascript">
        $(function () {
            $().SPServices({
                operation: "GetAttachmentCollection",
                async: false,
                listName: "Test",
                ID: 1,
                completefunc: function (xData, Status) {
                    //suppose only one attachement file
                    $(xData.responseXML).find("Attachment").each(function () {
                        var url = $(this).text();

                        var request = new XMLHttpRequest();
                        request.open('GET', url, true);
                        request.responseType = 'blob';
                        request.onload = function () {
                            var reader = new FileReader();
                            reader.readAsDataURL(request.response);
                            reader.onload = function (e) {
                                //binary stream
                                console.log('DataURL:', e.target.result);
                            };
                        };
                        request.send();
                    });

                }
            });
        })
    </script>

Update:

Test result.

enter image description here

2
  • does this return binary stream in base 64 format? – Ali Jun 30 '20 at 7:28
  • Check the update. – Lee_MSFT Jun 30 '20 at 8:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.