Uploadcollection sending files but can't be opened?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















Here is the thing. I'm trying to upload and send files from my app to a sap gateway by using UploadCollection sapui5 and a post request using ajax.



I was asked to send every single file in a xstring format (one by one), so the backend service can return a proper response.



This is how I'm trying to get the uploaded files content



new sap.m.UploadCollection({
id: 'upFiles',
numberOfAttachmentsText: 'Adjuntar archivos',
showSeparators: 'All',
fileType: ['jpg','jpeg','png','pdf','ods','pptx','xlsm','docx','doc', 'odt', 'docm','ppt','xlsx','rar','zip'],
noDataText: 'No se han cargado archivos todavia',
class: 'docpago-upload',
uploadUrl: '/sap/opu/odata/SAP/ZGWRE_WF_FILES_SRV/WfFileCollectionSet',
maximumFilenameLength: 120,
maximumFileSize: 10,
multiple: true,
uploadEnabled: true,
terminationEnabled: true,
change: function(oEvent) {

var file = oEvent.getParameter("files");
var numfiles = oEvent.getParameter("files").length;
}
});


And this is how I'm trying to send files through an ajax post request



                                                jQuery.ajax({
url: sUrlUpload,
type: "POST",
data: file, //Files I want to send
contentType: "application/json",
datatype : "text",
headers: {
'X-CSRF-Token': token, //token generated to send request
'slug': slug //a parameter I need to do some stuff
},
success: function (data, textStatus, XMLHttpRequest) {
console.log('Uploaded files: ' + JSON.stringify(data));


},
error: function(oError) {
console.log('Error: ' + JSON.stringify(oError.responseText))
}
});


For some reason, In the sap gateway side, files are successfully uploaded but not even single one can be open because the programs say "invalid format", "corrupted file" etc etc. And I think is because I'm not passing the file's content in a proper way. Any idea what could be wrong?










share|improve this question































    0















    Here is the thing. I'm trying to upload and send files from my app to a sap gateway by using UploadCollection sapui5 and a post request using ajax.



    I was asked to send every single file in a xstring format (one by one), so the backend service can return a proper response.



    This is how I'm trying to get the uploaded files content



    new sap.m.UploadCollection({
    id: 'upFiles',
    numberOfAttachmentsText: 'Adjuntar archivos',
    showSeparators: 'All',
    fileType: ['jpg','jpeg','png','pdf','ods','pptx','xlsm','docx','doc', 'odt', 'docm','ppt','xlsx','rar','zip'],
    noDataText: 'No se han cargado archivos todavia',
    class: 'docpago-upload',
    uploadUrl: '/sap/opu/odata/SAP/ZGWRE_WF_FILES_SRV/WfFileCollectionSet',
    maximumFilenameLength: 120,
    maximumFileSize: 10,
    multiple: true,
    uploadEnabled: true,
    terminationEnabled: true,
    change: function(oEvent) {

    var file = oEvent.getParameter("files");
    var numfiles = oEvent.getParameter("files").length;
    }
    });


    And this is how I'm trying to send files through an ajax post request



                                                    jQuery.ajax({
    url: sUrlUpload,
    type: "POST",
    data: file, //Files I want to send
    contentType: "application/json",
    datatype : "text",
    headers: {
    'X-CSRF-Token': token, //token generated to send request
    'slug': slug //a parameter I need to do some stuff
    },
    success: function (data, textStatus, XMLHttpRequest) {
    console.log('Uploaded files: ' + JSON.stringify(data));


    },
    error: function(oError) {
    console.log('Error: ' + JSON.stringify(oError.responseText))
    }
    });


    For some reason, In the sap gateway side, files are successfully uploaded but not even single one can be open because the programs say "invalid format", "corrupted file" etc etc. And I think is because I'm not passing the file's content in a proper way. Any idea what could be wrong?










    share|improve this question



























      0












      0








      0








      Here is the thing. I'm trying to upload and send files from my app to a sap gateway by using UploadCollection sapui5 and a post request using ajax.



      I was asked to send every single file in a xstring format (one by one), so the backend service can return a proper response.



      This is how I'm trying to get the uploaded files content



      new sap.m.UploadCollection({
      id: 'upFiles',
      numberOfAttachmentsText: 'Adjuntar archivos',
      showSeparators: 'All',
      fileType: ['jpg','jpeg','png','pdf','ods','pptx','xlsm','docx','doc', 'odt', 'docm','ppt','xlsx','rar','zip'],
      noDataText: 'No se han cargado archivos todavia',
      class: 'docpago-upload',
      uploadUrl: '/sap/opu/odata/SAP/ZGWRE_WF_FILES_SRV/WfFileCollectionSet',
      maximumFilenameLength: 120,
      maximumFileSize: 10,
      multiple: true,
      uploadEnabled: true,
      terminationEnabled: true,
      change: function(oEvent) {

      var file = oEvent.getParameter("files");
      var numfiles = oEvent.getParameter("files").length;
      }
      });


      And this is how I'm trying to send files through an ajax post request



                                                      jQuery.ajax({
      url: sUrlUpload,
      type: "POST",
      data: file, //Files I want to send
      contentType: "application/json",
      datatype : "text",
      headers: {
      'X-CSRF-Token': token, //token generated to send request
      'slug': slug //a parameter I need to do some stuff
      },
      success: function (data, textStatus, XMLHttpRequest) {
      console.log('Uploaded files: ' + JSON.stringify(data));


      },
      error: function(oError) {
      console.log('Error: ' + JSON.stringify(oError.responseText))
      }
      });


      For some reason, In the sap gateway side, files are successfully uploaded but not even single one can be open because the programs say "invalid format", "corrupted file" etc etc. And I think is because I'm not passing the file's content in a proper way. Any idea what could be wrong?










      share|improve this question
















      Here is the thing. I'm trying to upload and send files from my app to a sap gateway by using UploadCollection sapui5 and a post request using ajax.



      I was asked to send every single file in a xstring format (one by one), so the backend service can return a proper response.



      This is how I'm trying to get the uploaded files content



      new sap.m.UploadCollection({
      id: 'upFiles',
      numberOfAttachmentsText: 'Adjuntar archivos',
      showSeparators: 'All',
      fileType: ['jpg','jpeg','png','pdf','ods','pptx','xlsm','docx','doc', 'odt', 'docm','ppt','xlsx','rar','zip'],
      noDataText: 'No se han cargado archivos todavia',
      class: 'docpago-upload',
      uploadUrl: '/sap/opu/odata/SAP/ZGWRE_WF_FILES_SRV/WfFileCollectionSet',
      maximumFilenameLength: 120,
      maximumFileSize: 10,
      multiple: true,
      uploadEnabled: true,
      terminationEnabled: true,
      change: function(oEvent) {

      var file = oEvent.getParameter("files");
      var numfiles = oEvent.getParameter("files").length;
      }
      });


      And this is how I'm trying to send files through an ajax post request



                                                      jQuery.ajax({
      url: sUrlUpload,
      type: "POST",
      data: file, //Files I want to send
      contentType: "application/json",
      datatype : "text",
      headers: {
      'X-CSRF-Token': token, //token generated to send request
      'slug': slug //a parameter I need to do some stuff
      },
      success: function (data, textStatus, XMLHttpRequest) {
      console.log('Uploaded files: ' + JSON.stringify(data));


      },
      error: function(oError) {
      console.log('Error: ' + JSON.stringify(oError.responseText))
      }
      });


      For some reason, In the sap gateway side, files are successfully uploaded but not even single one can be open because the programs say "invalid format", "corrupted file" etc etc. And I think is because I'm not passing the file's content in a proper way. Any idea what could be wrong?







      javascript file sapui5






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 16 '18 at 18:46







      devtester

















      asked Nov 16 '18 at 18:39









      devtesterdevtester

      287




      287
























          1 Answer
          1






          active

          oldest

          votes


















          0














          How does your MGW_APPL_SRV_RUNTIME~CREATE_STREAM implementation looks like?



          Should be something like this:



            METHOD /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CREATE_STREAM.
          DATA: ls_key_tab TYPE /iwbep/s_mgw_name_value_pair,
          lt_key_tab TYPE /iwbep/t_mgw_name_value_pair,
          ls_document TYPE <YOUR TABLE>,
          lv_documentid TYPE char100.

          CASE iv_entity_name.
          WHEN '<YOUR ENTITY NAME>'.
          READ TABLE it_key_tab WITH KEY name = 'DocumentId' INTO ls_key_tab.

          ls_document-documentid = ls_key_tab-value.
          ls_document-mimetype = is_media_resource-mime_type.
          ls_document-filename = iv_slug.
          ls_document-value = is_media_resource-value.
          ls_document-sydate = sy-datum.
          ls_document-sytime = sy-uzeit.
          DELETE FROM <YOUR TABLE> WHERE documentid = ls_document-documentid.
          INSERT INTO <YOUR TABLE> VALUES ls_document.

          fileupdset_get_entity(
          EXPORTING
          iv_entity_name = iv_entity_name
          iv_entity_set_name = iv_entity_set_name
          iv_source_name = iv_source_name
          it_key_tab = it_key_tab
          it_navigation_path = it_navigation_path
          IMPORTING
          er_entity = ls_document ).

          copy_data_to_ref( EXPORTING is_data = ls_document
          CHANGING cr_data = er_entity ).
          ENDCASE.

          ENDMETHOD.


          On your table you should have a field, something like DocumentId that will serve as primary key.



          You can then call the url "/sap/opu/odata/SAP/ZGWRE_WF_FILES_SRV/WfFileCollectionSet('DocumentIdHere')"



          To retrieve the file you can simply make a GET request to the url "/sap/opu/odata/SAP/ZGWRE_WF_FILES_SRV/WfFileCollectionSet('DocumentIdHere')/$value"



          Good examples here and here. Hope that helps!






          share|improve this answer
























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53343617%2fuploadcollection-sending-files-but-cant-be-opened%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            How does your MGW_APPL_SRV_RUNTIME~CREATE_STREAM implementation looks like?



            Should be something like this:



              METHOD /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CREATE_STREAM.
            DATA: ls_key_tab TYPE /iwbep/s_mgw_name_value_pair,
            lt_key_tab TYPE /iwbep/t_mgw_name_value_pair,
            ls_document TYPE <YOUR TABLE>,
            lv_documentid TYPE char100.

            CASE iv_entity_name.
            WHEN '<YOUR ENTITY NAME>'.
            READ TABLE it_key_tab WITH KEY name = 'DocumentId' INTO ls_key_tab.

            ls_document-documentid = ls_key_tab-value.
            ls_document-mimetype = is_media_resource-mime_type.
            ls_document-filename = iv_slug.
            ls_document-value = is_media_resource-value.
            ls_document-sydate = sy-datum.
            ls_document-sytime = sy-uzeit.
            DELETE FROM <YOUR TABLE> WHERE documentid = ls_document-documentid.
            INSERT INTO <YOUR TABLE> VALUES ls_document.

            fileupdset_get_entity(
            EXPORTING
            iv_entity_name = iv_entity_name
            iv_entity_set_name = iv_entity_set_name
            iv_source_name = iv_source_name
            it_key_tab = it_key_tab
            it_navigation_path = it_navigation_path
            IMPORTING
            er_entity = ls_document ).

            copy_data_to_ref( EXPORTING is_data = ls_document
            CHANGING cr_data = er_entity ).
            ENDCASE.

            ENDMETHOD.


            On your table you should have a field, something like DocumentId that will serve as primary key.



            You can then call the url "/sap/opu/odata/SAP/ZGWRE_WF_FILES_SRV/WfFileCollectionSet('DocumentIdHere')"



            To retrieve the file you can simply make a GET request to the url "/sap/opu/odata/SAP/ZGWRE_WF_FILES_SRV/WfFileCollectionSet('DocumentIdHere')/$value"



            Good examples here and here. Hope that helps!






            share|improve this answer




























              0














              How does your MGW_APPL_SRV_RUNTIME~CREATE_STREAM implementation looks like?



              Should be something like this:



                METHOD /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CREATE_STREAM.
              DATA: ls_key_tab TYPE /iwbep/s_mgw_name_value_pair,
              lt_key_tab TYPE /iwbep/t_mgw_name_value_pair,
              ls_document TYPE <YOUR TABLE>,
              lv_documentid TYPE char100.

              CASE iv_entity_name.
              WHEN '<YOUR ENTITY NAME>'.
              READ TABLE it_key_tab WITH KEY name = 'DocumentId' INTO ls_key_tab.

              ls_document-documentid = ls_key_tab-value.
              ls_document-mimetype = is_media_resource-mime_type.
              ls_document-filename = iv_slug.
              ls_document-value = is_media_resource-value.
              ls_document-sydate = sy-datum.
              ls_document-sytime = sy-uzeit.
              DELETE FROM <YOUR TABLE> WHERE documentid = ls_document-documentid.
              INSERT INTO <YOUR TABLE> VALUES ls_document.

              fileupdset_get_entity(
              EXPORTING
              iv_entity_name = iv_entity_name
              iv_entity_set_name = iv_entity_set_name
              iv_source_name = iv_source_name
              it_key_tab = it_key_tab
              it_navigation_path = it_navigation_path
              IMPORTING
              er_entity = ls_document ).

              copy_data_to_ref( EXPORTING is_data = ls_document
              CHANGING cr_data = er_entity ).
              ENDCASE.

              ENDMETHOD.


              On your table you should have a field, something like DocumentId that will serve as primary key.



              You can then call the url "/sap/opu/odata/SAP/ZGWRE_WF_FILES_SRV/WfFileCollectionSet('DocumentIdHere')"



              To retrieve the file you can simply make a GET request to the url "/sap/opu/odata/SAP/ZGWRE_WF_FILES_SRV/WfFileCollectionSet('DocumentIdHere')/$value"



              Good examples here and here. Hope that helps!






              share|improve this answer


























                0












                0








                0







                How does your MGW_APPL_SRV_RUNTIME~CREATE_STREAM implementation looks like?



                Should be something like this:



                  METHOD /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CREATE_STREAM.
                DATA: ls_key_tab TYPE /iwbep/s_mgw_name_value_pair,
                lt_key_tab TYPE /iwbep/t_mgw_name_value_pair,
                ls_document TYPE <YOUR TABLE>,
                lv_documentid TYPE char100.

                CASE iv_entity_name.
                WHEN '<YOUR ENTITY NAME>'.
                READ TABLE it_key_tab WITH KEY name = 'DocumentId' INTO ls_key_tab.

                ls_document-documentid = ls_key_tab-value.
                ls_document-mimetype = is_media_resource-mime_type.
                ls_document-filename = iv_slug.
                ls_document-value = is_media_resource-value.
                ls_document-sydate = sy-datum.
                ls_document-sytime = sy-uzeit.
                DELETE FROM <YOUR TABLE> WHERE documentid = ls_document-documentid.
                INSERT INTO <YOUR TABLE> VALUES ls_document.

                fileupdset_get_entity(
                EXPORTING
                iv_entity_name = iv_entity_name
                iv_entity_set_name = iv_entity_set_name
                iv_source_name = iv_source_name
                it_key_tab = it_key_tab
                it_navigation_path = it_navigation_path
                IMPORTING
                er_entity = ls_document ).

                copy_data_to_ref( EXPORTING is_data = ls_document
                CHANGING cr_data = er_entity ).
                ENDCASE.

                ENDMETHOD.


                On your table you should have a field, something like DocumentId that will serve as primary key.



                You can then call the url "/sap/opu/odata/SAP/ZGWRE_WF_FILES_SRV/WfFileCollectionSet('DocumentIdHere')"



                To retrieve the file you can simply make a GET request to the url "/sap/opu/odata/SAP/ZGWRE_WF_FILES_SRV/WfFileCollectionSet('DocumentIdHere')/$value"



                Good examples here and here. Hope that helps!






                share|improve this answer













                How does your MGW_APPL_SRV_RUNTIME~CREATE_STREAM implementation looks like?



                Should be something like this:



                  METHOD /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CREATE_STREAM.
                DATA: ls_key_tab TYPE /iwbep/s_mgw_name_value_pair,
                lt_key_tab TYPE /iwbep/t_mgw_name_value_pair,
                ls_document TYPE <YOUR TABLE>,
                lv_documentid TYPE char100.

                CASE iv_entity_name.
                WHEN '<YOUR ENTITY NAME>'.
                READ TABLE it_key_tab WITH KEY name = 'DocumentId' INTO ls_key_tab.

                ls_document-documentid = ls_key_tab-value.
                ls_document-mimetype = is_media_resource-mime_type.
                ls_document-filename = iv_slug.
                ls_document-value = is_media_resource-value.
                ls_document-sydate = sy-datum.
                ls_document-sytime = sy-uzeit.
                DELETE FROM <YOUR TABLE> WHERE documentid = ls_document-documentid.
                INSERT INTO <YOUR TABLE> VALUES ls_document.

                fileupdset_get_entity(
                EXPORTING
                iv_entity_name = iv_entity_name
                iv_entity_set_name = iv_entity_set_name
                iv_source_name = iv_source_name
                it_key_tab = it_key_tab
                it_navigation_path = it_navigation_path
                IMPORTING
                er_entity = ls_document ).

                copy_data_to_ref( EXPORTING is_data = ls_document
                CHANGING cr_data = er_entity ).
                ENDCASE.

                ENDMETHOD.


                On your table you should have a field, something like DocumentId that will serve as primary key.



                You can then call the url "/sap/opu/odata/SAP/ZGWRE_WF_FILES_SRV/WfFileCollectionSet('DocumentIdHere')"



                To retrieve the file you can simply make a GET request to the url "/sap/opu/odata/SAP/ZGWRE_WF_FILES_SRV/WfFileCollectionSet('DocumentIdHere')/$value"



                Good examples here and here. Hope that helps!







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 19 '18 at 10:00









                Andre FAndre F

                2961214




                2961214
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53343617%2fuploadcollection-sending-files-but-cant-be-opened%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Florida Star v. B. J. F.

                    Danny Elfman

                    Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues