<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      ABAP調用HTTP接口上傳文件

      一、Java上傳文件的的接口

      Controller

      package org.jeecg.modules.ncip.controller;
      
      import javax.servlet.http.HttpServletRequest;
      
      import org.jeecg.common.api.vo.Result;
      import org.jeecg.modules.ncip.service.FileService;
      import org.springframework.beans.factory.annotation.Autowired;
      import org.springframework.web.bind.annotation.RequestMapping;
      import org.springframework.web.bind.annotation.RequestMethod;
      import org.springframework.web.bind.annotation.RequestParam;
      import org.springframework.web.bind.annotation.RestController;
      import org.springframework.web.multipart.MultipartFile;
      
      /**
       * @author Amell
       * 2023年6月2日 下午4:10:27 
       * 
       */
      @RestController
      @RequestMapping("/ncip/file")
      public class FileController {
          
          @Autowired
          private FileService fileSerive;
          
          @RequestMapping(value = "/upload", method = RequestMethod.POST)
          public Result<?> uploadFile(@RequestParam MultipartFile file,HttpServletRequest req) {
              Result<?> result = fileSerive.uploadFile(file);
              return result;        
          }
      
      }
      View Code

      Service

      package org.jeecg.modules.ncip.service;
      
      import org.jeecg.common.api.vo.Result;
      import org.springframework.web.multipart.MultipartFile;
      
      /**
       * @author Amell
       * 2023年6月2日 下午5:28:58 
       * 
       */
      
      public interface FileService {
      
          Result<?> uploadFile(MultipartFile file);
      
      }
      View Code

      ServiceImpl

      package org.jeecg.modules.ncip.service.impl;
      
      import java.io.File;
      import java.io.IOException;
      import java.net.URLDecoder;
      import java.text.SimpleDateFormat;
      import java.util.Date;
      
      import org.jeecg.common.api.vo.Result;
      import org.jeecg.modules.ncip.service.FileService;
      import org.springframework.stereotype.Service;
      import org.springframework.web.multipart.MultipartFile;
      
      
      /**
       * @author Amell
       * 2023年6月2日 下午5:29:22 
       * 
       */
      @Service
      public class FileServiceImpl implements FileService{
      
          @Override
          public Result<?> uploadFile(MultipartFile file) {
              
              Result<?> result= new Result<>();
              
              //絕對路徑
              String realPath = "http://192.168.194.12/File/";
              SimpleDateFormat sdf=new SimpleDateFormat("YYYYMM");
              String format=sdf.format(new Date());
              
              //文件存放的目錄(在絕對路徑下建立年月名稱的文件夾)
              File folder = new File(realPath+format);
              if(!folder.isDirectory()) {
                  folder.mkdir();
              }
              
              try {
                  //文件名
                  String fileName = file.getOriginalFilename();
                  
                  //文件后綴
                  //String suffix = fileName.substring(fileName.lastIndexOf("."),fileName.length());
                  
                  //utf-8解碼
                  fileName = URLDecoder.decode(fileName,"UTF-8");
                  
                  //文件存在則先刪除后再建立
                  File targetFile = new File(folder,fileName);
                  if(!targetFile.exists()) {
                      targetFile.mkdirs();
                  }else {
                      targetFile.delete();
                  }
                  file.transferTo(targetFile);
                  result.setSuccess(true);
              } catch (IOException e) {
                  e.printStackTrace();
                  result.error500("上傳文件失敗");
              }       
              
              return result;
          }
      
      }
      View Code

      二、Postman測試

      http的headers添加token驗證

      http的body選擇form-data,在key里點擊下拉按鈕,選擇File

      填寫key名稱(這里要跟Java接口的參數名一樣),并點擊select files選擇文件

      選擇文件后點擊send,看下接口返回的結果

      點擊code查看http代碼,接下來就是要用http的代碼來寫abap

      三、ABAP調用http接口上傳文件

      效果:

      代碼:

      ************************************************************************
      * 程 序 名:
      * 程序描述:ABAP調用http接口上傳文件
      * 事務代碼:
      ************************************************************************
      * 修改日志
      ************************************************************************
      * 日期     版本 修改人       描述
      * -------- ---- ------------ -------------------------------------------
      * 20230607 1.0  Amell        創建程序
      *
      ************************************************************************
      REPORT zhttp_test MESSAGE-ID 00.
      
      ************************************************************************
      * Tables Definitions
      ************************************************************************
      TABLES: rlgrap.
      
      ************************************************************************
      * Data Definitions                定義數據
      ************************************************************************
      TYPES: BEGIN OF ty_file,
               line(1024) TYPE x,
             END OF ty_file.
      
      DATA: gt_file TYPE TABLE OF ty_file.
      
      DATA: gv_file_name TYPE sdbah-actid,
            gv_file_type TYPE sdbad-funct,
            gv_file      TYPE xstring.
      
      ************************************************************************
      * Includes Module                 包含模塊
      ************************************************************************
      
      ************************************************************************
      * Selection Screen                選擇屏幕
      ************************************************************************
      PARAMETERS: p_file LIKE rlgrap-filename OBLIGATORY.
      
      ************************************************************************
      * Initialization                  初始化事件
      ************************************************************************
      INITIALIZATION.
      
      ************************************************************************
      * At Selection Screen             PAI事件
      ************************************************************************
      AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
        PERFORM frm_f4_file.
      
      ************************************************************************
      * At Selection Screen Output      PBO事件
      ************************************************************************
      AT SELECTION-SCREEN OUTPUT.
      
      ************************************************************************
      * Report Format                   報表格式
      ************************************************************************
      TOP-OF-PAGE.
      
      END-OF-PAGE.
      
      ************************************************************************
      * Main Process                    主要邏輯
      ************************************************************************
      START-OF-SELECTION.
      
        "讀取上傳文件
        PERFORM frm_read_upload_file.
        "調用http接口上傳文件
        PERFORM frm_call_http_to_upload_file.
      
      END-OF-SELECTION.
      
      *&---------------------------------------------------------------------*
      *& Form FRM_F4_FILE
      *&---------------------------------------------------------------------*
      *& text
      *&---------------------------------------------------------------------*
      *& -->  p1        text
      *& <--  p2        text
      *&---------------------------------------------------------------------*
      FORM frm_f4_file .
        CALL FUNCTION 'F4_FILENAME'
          IMPORTING
            file_name = p_file.
      ENDFORM.
      
      *&---------------------------------------------------------------------*
      *& Form FRM_READ_UPLOAD_FILE
      *&---------------------------------------------------------------------*
      *& text
      *&---------------------------------------------------------------------*
      *& -->  p1        text
      *& <--  p2        text
      *&---------------------------------------------------------------------*
      FORM frm_read_upload_file .
      
        DATA: lv_file_path   TYPE string,
              lv_file_length TYPE i,
              lv_file_name   TYPE dbmsgora-filename.
      
        lv_file_path = p_file.
        lv_file_name = p_file.
      
        CALL FUNCTION 'SPLIT_FILENAME'
          EXPORTING
            long_filename  = lv_file_name "上傳文件路徑
          IMPORTING
            pure_filename  = gv_file_name "文件名稱
            pure_extension = gv_file_type. "文件后綴
      
        CALL FUNCTION 'GUI_UPLOAD'
          EXPORTING
            filename                = lv_file_path
            filetype                = 'BIN'
          IMPORTING
            filelength              = lv_file_length
          TABLES
            data_tab                = gt_file
          EXCEPTIONS
            file_open_error         = 1
            file_read_error         = 2
            no_batch                = 3
            gui_refuse_filetransfer = 4
            invalid_type            = 5
            no_authority            = 6
            unknown_error           = 7
            bad_data_format         = 8
            header_not_allowed      = 9
            separator_not_allowed   = 10
            header_too_long         = 11
            unknown_dp_error        = 12
            access_denied           = 13
            dp_out_of_memory        = 14
            disk_full               = 15
            dp_timeout              = 16
            OTHERS                  = 17.
        IF sy-subrc <> 0.
          MESSAGE s001 WITH '上傳文件失敗' DISPLAY LIKE 'E'.
          LEAVE LIST-PROCESSING.
        ENDIF.
      
        "轉xstring
        CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
          EXPORTING
            input_length = lv_file_length
          IMPORTING
            buffer       = gv_file
          TABLES
            binary_tab   = gt_file
          EXCEPTIONS
            failed       = 1
            OTHERS       = 2.
        IF sy-subrc <> 0.
          MESSAGE s001 WITH '轉xstring失敗' DISPLAY LIKE 'E'.
          LEAVE LIST-PROCESSING.
        ENDIF.
      
      
      ENDFORM.
      
      *&---------------------------------------------------------------------*
      *& Form FRM_CALL_HTTP_TO_UPLOAD_FILE
      *&---------------------------------------------------------------------*
      *& text
      *&---------------------------------------------------------------------*
      *& -->  p1        text
      *& <--  p2        text
      *&---------------------------------------------------------------------*
      FORM frm_call_http_to_upload_file .
      
        DATA: lo_http_client TYPE REF TO if_http_client, "http客戶端
              lo_http_entity TYPE REF TO if_http_entity, "http實體
              lt_http_header TYPE tihttpnvp,             "http頭部信息
              ls_http_header TYPE ihttpnvp,
              lv_url         TYPE string,                "http請求
              lv_len         TYPE i,                     "請求數據的長度
              lv_response    TYPE string,                "http響應返回信息
              lv_code        TYPE i.                     "http狀態碼
      
        DATA: lv_error_code TYPE sysubrc,
              lv_error_msg  TYPE string.
      
        DATA: lv_file_name TYPE savwctxt-fieldcont,
              lv_name_encode TYPE savwctxt-fieldcont.
      
        DATA: lv_content_disposition TYPE string,
              lv_content_type        TYPE string.
      
        lv_url = 'http://192.168.194.12:8080/jeecg-boot/ncip/file/upload'.
      
        "創建http客戶端請求
        CALL METHOD cl_http_client=>create_by_url
          EXPORTING
            url                = lv_url
          IMPORTING
            client             = lo_http_client
          EXCEPTIONS
            argument_not_found = 1
            plugin_not_active  = 2
            internal_error     = 3
            OTHERS             = 4.
      
        "設置http為post請求
        lo_http_client->request->set_method( 'POST' ).
      
        ls_http_header-name = 'X-Access-Token'.
        ls_http_header-value = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2ODYxODM1OTcsInVzZXJuYW1lIjoiYWRtaW4ifQ.fpxtvBsFDVR5WmjP3iLXhD-K7ZiULofqwQ1S_DE9Hxk'.
        APPEND ls_http_header TO lt_http_header.
      
        ls_http_header-name = 'Content-Type'.
        ls_http_header-value = 'multipart/form-data'.
        APPEND ls_http_header TO lt_http_header.
      
        "設置http header
        CALL METHOD lo_http_client->request->set_header_fields
          EXPORTING
            fields = lt_http_header.
      
      *  CALL METHOD lo_http_client->request->if_http_entity~set_formfield_encoding
      *    EXPORTING
      *      formfield_encoding = cl_http_request=>if_http_entity~co_encoding_raw.
      
        lo_http_entity = lo_http_client->request->if_http_entity~add_multipart( ).
      
        "utf-8編碼文件名(目的是讓上傳后的文件名跟原來一樣,不然會亂碼)
        lv_file_name = gv_file_name.
        CALL FUNCTION 'WWW_URLENCODE'
          EXPORTING
            value         = lv_file_name
          IMPORTING
            value_encoded = lv_name_encode.
      
        lv_content_disposition = 'form-data; name="file"; filename="' && lv_name_encode && '.' && gv_file_type && '"'.
      
        CALL METHOD lo_http_entity->set_header_field
          EXPORTING
            name  = 'Content-Disposition'
            "value = 'form-data; name="file"; filename="測試文件.pdf"'
            value = lv_content_disposition.
      
        "文件后綴轉小寫
        TRANSLATE gv_file_type TO LOWER CASE.
      
        CASE gv_file_type.
          WHEN 'jpg'.
            lv_content_type = 'image/jpeg'.
          WHEN 'png'.
            lv_content_type = 'image/png'.
          WHEN 'txt'.
            lv_content_type = 'text/plain'.
          WHEN 'pdf'.
            lv_content_type = 'application/pdf'.
          WHEN 'xlsx'.
            lv_content_type = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'.
          WHEN 'xls'.
            lv_content_type = 'application/vnd.ms-excel'.
          WHEN 'docx'.
            lv_content_type = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'.
          WHEN 'doc'.
            lv_content_type = 'application/msword'.
        ENDCASE.
      
        CALL METHOD lo_http_entity->set_content_type
          EXPORTING
            content_type = lv_content_type.
      
        lv_len = xstrlen( gv_file ).
      
        CALL METHOD lo_http_entity->set_data
          EXPORTING
            data   = gv_file
            offset = 0
            length = lv_len.
      
        "發送請求
        CALL METHOD lo_http_client->send
          EXCEPTIONS
            http_communication_failure = 1
            http_invalid_state         = 2
            http_processing_failed     = 3
            http_invalid_timeout       = 4
            OTHERS                     = 5.
      
        IF sy-subrc NE 0.
      
          CALL METHOD lo_http_client->get_last_error
            IMPORTING
              code    = lv_error_code
              message = lv_error_msg.
      
        ENDIF.
      
        "請求返回結果
        CALL METHOD lo_http_client->receive
          EXCEPTIONS
            http_communication_failure = 1
            http_invalid_state         = 2
            http_processing_failed     = 3.
      
        "請求返回的狀態碼
        CALL METHOD lo_http_client->response->get_status
          IMPORTING
            code = lv_code.
      
        "獲取接口返回的數據
        lv_response = lo_http_client->response->get_cdata( ).
      
        cl_demo_output=>write( lv_response ).
      
        cl_demo_output=>display(  ).
      
      ENDFORM.

       

      posted @ 2023-06-08 09:12  鯨與海  閱讀(2725)  評論(11)    收藏  舉報
      主站蜘蛛池模板: 国产日韩精品一区二区三区在线| 高清在线一区二区三区视频| 麻豆国产va免费精品高清在线| 欧日韩无套内射变态| 四虎永久在线精品无码视频| 欧美老人巨大XXXX做受视频| 人妻中文字幕亚洲一区| 亚洲av成人一区二区三区| 国产又色又爽又黄的免费软件| 国产精品污双胞胎在线观看| V一区无码内射国产| 亚洲色大成网站www在线| 小污女小欲女导航| 午夜三级成人在线观看| 日韩av熟女人妻一区二| 中文字幕第一页国产| 久久久久蜜桃精品成人片公司| 99久久er热在这里只有精品99 | 国产午夜精品理论大片| 中文字幕在线日韩一区| 亚洲欧美国产精品久久久久久久 | 性姿势真人免费视频放| 国产亚洲精品AA片在线爽| 甘南县| 蜜臀av性久久久久蜜臀aⅴ麻豆 | 强开少妇嫩苞又嫩又紧九色| 国产一区二区日韩在线| 奇米四色7777中文字幕| 真人无码作爱免费视频| 亚洲的天堂在线中文字幕| 茄子视频国产在线观看| 亚洲中文字幕在线二页| 国产精品自拍一二三四区| 国精品午夜福利视频不卡| 日韩免费码中文在线观看| 国产不卡一区不卡二区| 九九热精品视频在线免费| 免费国产一区二区不卡| 久久精品国产再热青青青| 国产日韩精品免费二三氏| 国产极品粉嫩福利姬萌白酱|