cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

File Upload from Local drive to MII WEB Folder

Former Member
0 Kudos
1,282

Hi All,

I am new to SAP MII and I searched a lot for the file upload on SCN, I also saw a couple of code snippets.

I tried using the Apache APIs, but couldn't make it work.

I have a code that I borrowed from a related thread, I just would like to ask how is the below code of JSP getting the filename ?

<%@ page import = "java.io.*" %>

<%@ page import = "java.util.*"%>

<%@ page import = "java.net.URLEncoder"%>

<%@ page import = "javax.servlet.*"%>

<%@ page import = "javax.servlet.http.*"%>

<%@ page import = "javax.naming.*"%>

<%@ page import = "javax.sql.*"%>

<%@ page import = "java.sql.*"%>

<% String contentType = request.getContentType();

    if( (contentType != null) && (contentType.indexOf("multipart/form-data") >= 0 ) )

{

  DataInputStream in = new DataInputStream( request.getInputStream() );

  int formDataLength = request.getContentLength();

  byte dataBytes[] = new byte[ formDataLength ];

  int byteRead = 0;

  int totalBytesRead = 0;

  byteRead = in.read( dataBytes, 0 ,formDataLength );

  String httpPostContent = new String( dataBytes );

  String fileName = httpPostContent.substring( httpPostContent.indexOf("fileName=\"")+10);

  fileName = fileName.substring( 0, fileName, indexOf("\n") );

  fileName = fileName.substring( fileName.lastIndexOf("\\") + 1, fileName.indexOf( "\"" ));

  int length = dataBytes.length;

  int lastIndex = contentType.lastIndexOf( "=" );

  String boundary = contentType.substring( lastIndex + 1, contentType.length() );

  int pos;

  pos = httpPostContent.indexOf( "fileName=\"");

  pos = httpPostContent.indexOf( "\n", pos) + 1;

  pos = httpPostContent.indexOf( "\n", pos) + 1;

  pos = httpPostContent.indexOf( "\n", pos) + 1;

  int boundaryLocation = httpPostContent.indexOf( boundary, pos ) - 4;

  int startPos = ( ( httpPostContent.substring( 0, pos )).getBytes()).length;

  int endPos = ( ( httpPostContent.substring( 0, boundaryLocation )).getBytes()).length;

  String output = URLEncoder.encode( httpPostContent.substring( startPos, endPos ));

  String site = ("/XMII/Runner?Transaction=411186/WriteFileTrx&InFileName=" + fileName);

  response.sendRedirect(site);

  }

%>

Regards

Anish Vyas

View Entire Topic
senthil_kumar44
Participant
0 Kudos

Hello Anish,

You cant directly upload files in SAP MII workbench except Import / Export of MII workbench. If you are using SAPUI5 as web page, you can use FileUpload control. This control will allow to select file from local drive in running time and it will give encrypted output for that file. You can pass this content as input to transaction in MII and you can decrypt in transaction by using transaction expressions and you can save it in MII workbench.

Thanks,

Senthil

Former Member
0 Kudos

hi senthil,

Am also trying the same, what u have mentioned above. but am not clear in  mapping the selected file to transaction expression.

could u please explain a bit more?

regards,

Akalya

senthil_kumar44
Participant
0 Kudos

Hello Akalya,

In FileUpload control, when we select the file, it will modify that file into encrypted format. In transaction, set string input parameter and assign this encoded value into transaction string parameter. Once we received encoded value inside transaction, we can decode it and save.

We have done this for uploading data in CSV files from local drive to MDO database. It worked successfully.

Thanks,

Senthil

Former Member
0 Kudos

Hi Senthil,

I am not using SAPUI5, I am using a basic file type input from HTML5 using it to pass the file in multipart form to a JSP file where I am encoding the input and targeting it to a Input parameter in a transaction.

By looking into different posts regarding File Upload , I got to know the process. I was confused with Multi-part file transfer. I just have a few syntax errors. Then I'll be good to go. Still, thank you.

For reference :

Regards

Anish Vyas

Former Member
0 Kudos

thanks senthil.

actually now we are trying to upload excel data to MDO DB. I have used string_list_to_xml_parser action block in the transaction while giving inputs manually for the transaction in excel format it works.

now i want pass the input to the transaction using ui5 file uploader but i dont know how to assign the excel data to transaction parameter.

can you please share your ui5 code for my reference?

regards,

Akalya