none
attachment upload through Web API - httpResponsemessage RRS feed

  • Question

  • Hi,

    Uploading attachments to my mail app, by making a call to a web api route is not attaching the document. The error code is  generic - 9007, The attachment cannot be added to the item, generalUploadFailure. I can download the file from the browser using that same route.

    I'm using the JavaScript Api method,  item.addFileAttachmentAsync.

    Anyone that has encountered the same problem?

    Thanks.


    Milton Cody

    Thursday, July 30, 2015 10:16 PM

Answers

  • Hi Milton,

    >> Do either of these endpoint values have to change to work the addFileAttachmentsAsync method?

    In my option, you need to change the endpoint value to the location of the file. Based on the API below, the URI parameter provides the location of the file to attach to the message. If you pass a stream content, it might not work.

    # Message.addFileAttachmentAsync method (JavaScript API for Office)
    https://msdn.microsoft.com/en-us/library/office/dn482510.aspx

    For a workaround, I think you could save the streamContent to a file in one position over the Internet, and then pass the file URI to the item.addFileAttachmentAsync.

    If this is a feature you want to include in future versions of app for Office, please submit a feedback to Office Development Platform Uservoice.
    http://officespdev.uservoice.com

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, August 3, 2015 7:48 AM

All replies

  • Hi Milton,

    >> Uploading attachments to my mail app, by making a call to a web api route is not attaching the document.

    What do you mean by “Uploading attachments to my mail app”? Do you mean you add an attachment to a message or an appointment or any other place? How do you use a call to web api route? Do you mean you create a web service for a mail app with web api?

    >> The error code is  generic - 9007, The attachment cannot be added to the item, generalUploadFailure.
    Could you share us steps or key code to reproduce your issue?

    >> I'm using the JavaScript Api method,  item.addFileAttachmentAsync.
    As far as I know, addFileAttachmentAsync is used to add attachments, I am not sure how it is related with Web api route. Do you mean that you use addFileAttachmentAsync to add a file which is in the internet and you pass the url of the file to the addFileAttachmentAsync method? If so, could you show me how you use? I made a test with this method, and it worked correctly. Here is a simple code.

    function addFile() {
        Office.context.mailbox.item.addFileAttachmentAsync("https://code.msdn.microsoft.com/Apps-for-Office-Create-a-ce255a96/file/83814/8/Apps%20for%20Office%20%20Create%20a%20web%20service%20using%20the%20ASP.NET%20Web%20API.zip", "test.zip");
    }

    If I misunderstood you, please feel free to let me know.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Friday, July 31, 2015 9:39 AM
  • Hi Edward,

    Yes, I mean to add an attachment to a message.

    I pass the Web Api route, which returns an httpresponsemessage, as the URI parameter to the addFileAttachmentAsync method.   

    item.addFileAttachmentAsync(
      attachmentUri, // this is the web api route
      params.fileName, // file name with extension
      { asyncContext: null },
      function (asyncResult) {
      if (asyncResult.status == OfficeAPI.AsyncResultStatus.Failed) {
     alertService.warning('Failed to attach document:' + asyncResult.error.message); }
     else {
           attachmentID.push(asyncResult.value);
           alertService.success('Attachment added to message, attachment ID: ' + asyncResult.value); }
    });
    The item.addFileAttachmentAsync works correctly when using a uri to gif files or other content. The httpresponsemessage is set to return the file as streamContent, with mimeType application/octet-stream. Do either of these endpoint values have to change to work the addFileAttachmentsAsync method?

    Milton Cody

    Friday, July 31, 2015 1:24 PM
  • Hi Milton,

    >> Do either of these endpoint values have to change to work the addFileAttachmentsAsync method?

    In my option, you need to change the endpoint value to the location of the file. Based on the API below, the URI parameter provides the location of the file to attach to the message. If you pass a stream content, it might not work.

    # Message.addFileAttachmentAsync method (JavaScript API for Office)
    https://msdn.microsoft.com/en-us/library/office/dn482510.aspx

    For a workaround, I think you could save the streamContent to a file in one position over the Internet, and then pass the file URI to the item.addFileAttachmentAsync.

    If this is a feature you want to include in future versions of app for Office, please submit a feedback to Office Development Platform Uservoice.
    http://officespdev.uservoice.com

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, August 3, 2015 7:48 AM
  • Hi Edward,

    I have a followup question. The addFileAttachmentAsync method, does this method send a soap request to EWS in a similar fashion as EWS Managed Api 2.0? Are there logs that I can view to figure out where these calls are erroring? The app plugin is able to reach the web api endpoints when not called from the addFileAttachmentAsync.

    Thanks

    Milton C.


    Milton Cody

    Monday, August 3, 2015 3:58 PM
  • Hi Milton,

    >> The addFileAttachmentAsync method, does this method send a soap request to EWS in a similar fashion as EWS Managed Api 2.0?

    I am afraid that it does not send a soap. In my option, there is a method called Mailbox.makeEwsRequestAsync method send a soap request. But not all EWS operations are supported in mail apps. You could refer the link below for more information.

    # Call web services from a mail add-in for Outlook
    https://msdn.microsoft.com/en-us/library/office/fp160952.aspx
    >> Are there logs that I can view to figure out where these calls are erroring?

    Based on the addFileAttachmentAsync  API, if you specify a callback method, the method will be called with one parameter, asyncResult, which contains either the identifier of the attachment or a code that indicates any error that occurred while uploading the attachment. You could get error from the asyncResult.

    Best Regards,

    Edward

     

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    Tuesday, August 4, 2015 5:35 AM