on 03-28-2014 9:24 AM
Hello Experts.
Could you please assist me on how to upload and save file on MII server?
I am looking for best and non-complex method of doing it.
Thanks in advance
Dear Experts,
Thanks for your valuable input!
Finally , I got his functionality working, but I need your assistance to make me correct where I am missing.
I got the BASE64 encoded string in a variable in JSP, now i am calling Transaction using Runner Call in JSP's response.sendRedirect() Method, but seems BAS64 string is distorting in between, it gives me Blurred image when generated via Xacute Engine, but if i directly copy the BASE64 string generated in my JSP code and put in directly to the input parameter of the MII transaction that has only image saver, it generates image perfectly, do you have any idea or way to call trx from JSP?
or any idea how to correct distorted BASE64 encoded string?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Christian,
I have one issue :
I want to send BASE64 string of more than 1KB file to MII transaction.
from the above method mentioned, I get the correct BASE64 encoded String on Print ln
But same string when I try to use as parameter assign to Query template ( I am calling Xacute query template instead of Runner Call)
it shows Page not found or 404 error, any idea ? for less than 1 KB files its working correct for me. but not sure about more than 1 KB . I suspect an issue in Xacute Query template call [may be].
or Runner is best to use in this scenario. Kindly assist me .
Thanks
i am using MII workbench as IDE and not eclipse,, so i am not sure if i can see the compilation error details , currently it shows some compiling error.
this function works perfect
str = java.net.URLEncoder.encode(str , "UTF-8");
all good, problem comes when i send URL encoded BASE64 string in a Query template call via sendRedirect of Servlet JSP method.
for long enocded string, sendRedirect does not work and shows "Page Not Found "
Hi Ayush,
Good Day!! Can you kindly share the sample code here because I have a same requirement of uploading a file into MII 14.0 Server and it is giving permission error. As you said, it works perfect for you, so I am seeing some hope here..
Will be very very helpful if you please share a sample code.
Best Regards,
Ushinar
---------------------------------------------JSP FILE-----------------------------------------------------------------------------------------
<html>
<head>
<meta http-equiv="Content-Type" content="text/html ; charset=iso-8859-1">
</head>
<body>
<%@ page import="java.io.*" %>
<%@ page import="com.sap.lhcommon.util.Base64Util" %>
<%
String saveFile="";
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;
while(totalBytesRead < formDataLength){
byteRead = in.read(dataBytes, totalBytesRead,formDataLength-totalBytesRead);
totalBytesRead += byteRead;
}
String file = new String(dataBytes);
saveFile = file.substring(file.indexOf("filename=\"") + 10);
saveFile = saveFile.substring(0, saveFile.indexOf("\n"));
saveFile = saveFile.substring(saveFile.lastIndexOf("\\") + 1,saveFile.indexOf("\""));
int lastIndex = contentType.lastIndexOf("=");
String boundary = contentType.substring(lastIndex + 1,contentType.length());
int pos;
pos = file.indexOf("filename=\"");
pos = file.indexOf("\n", pos) + 1;
pos = file.indexOf("\n", pos) + 1;
pos = file.indexOf("\n", pos) + 1;
int boundaryLocation = file.indexOf(boundary, pos) - 4;
int startPos = ((file.substring(0, pos)).getBytes()).length;
int endPos = ((file.substring(0, boundaryLocation)).getBytes()).length;
File ff = new File(saveFile);
FileOutputStream fileOut = new FileOutputStream(ff);
fileOut.write(dataBytes, startPos, (endPos - startPos));
fileOut.flush();
fileOut.close();
File f = new File(saveFile);
FileInputStream fis = new FileInputStream(f);
fis.read(dataBytes);
if(fis!=null){fis.close();}
String base64String = new String(Base64Util.encode(dataBytes),"UTF-8");
String project_key=request.getParameter("pkey");
if (project_key == null){project_key="-1";}
String projectName=request.getParameter("pname");
String fileName=new String(saveFile);
int extIndex=fileName.indexOf(".");
fileName=fileName.substring(extIndex+1);
String fileOption=fileName.toUpperCase();
if(fileOption.equals("JPG") || fileOption.equals("PNG") || fileOption.equals("BMP") || fileOption.equals("JPEG") || fileOption.equals("GIF") || fileOption.equals("TIFF")){
fileOption="JPG";
}
//String url=new String("http://serverName:50000/XMII/CM/FolderName/WorkRequestDashboard/Test.irpt?EncodedStr="+java.net.URLEncoder.encode(base64String));
//out.println(base64String);
//response.sendRedirect("http://serverName:50000/XMII/Illuminator?QueryTemplate=FolderName/WorkRequestDashboard/FileUpload_Xacute&Param.1="+java.net.URLEncoder.encode(base64String)+"&Param.2="+projectName+"&Param.3="+fileOption);
// response.sendRedirect("http://serverName:50000/XMII/Runner?Transaction=FolderName/WorkRequestDashboard/FILEUPLOAD&fileInput="+java.net.URLEncoder.encode(base64String)+"&projectName="+projectName+"&FileOption="+fileOption);
request.getRequestDispatcher("Test.irpt?EncodedStr="+java.net.URLEncoder.encode(base64String)+"&projectkey="+project_key+"&projectname="+projectName+ "&FileOption="+fileOption).forward(request,response);
}
%>
</body>
</html>
--------------------------------------TEST.IRPT-----------------------------------------------------------------------------
<html>
<head>
<meta http-equiv="Content-Type" content="text/html ; charset=iso-8859-1">
<title>File Upload Form</title>
<script lang="javascript">
function upload(){
var fi=document.getElementById("file").value;
var pk=document.getElementById("projectkey").value;
var fop=document.getElementById("fo").value;
var pn=document.getElementById("pn").value;
//alert(fi+'\n'+pn+'\n'+fop);
var uploadObj=document.FileUpload.getQueryObject();
uploadObj.setParam(1,fi);
uploadObj.setParam(2,pk);
uploadObj.setParam(3,fop);
uploadObj.setParam(4,pn);
if(document.FileUpload.executeCommand()){
document.getElementById("imsg").innerHTML="File Attached Successfully.";
alert(document.FileUpload.getValueByName("Output",1));
window.close();
}
else{
alert(document.FileUpload.getLastError());
return;
}
}
</script>
</head>
<input type="hidden" id="file" value="{EncodedStr}" >
<input type="hidden" id="projectkey" value="{projectkey}" >
<input type="hidden" id="fo" value="{FileOption}" >
<input type="hidden" id="pn" value="{projectname}" >
<body onload="upload();">
<span id="imsg"> </span>
</body >
<applet name="FileUpload" id="FileUpload" codebase="/XMII/Classes" code="iCommand" archive="illum8.zip" width="4" height="4" style="visibility: hidden">
<param name="QueryTemplate" value="FolderName/WorkRequestDashboard/FileUpload_Xacute">
</applet>
</html>
---------------------------------------------------------------------UPLOAD FORM .IRPT-----------------------------
<html>
<head>
<meta http-equiv="Content-Type" content="text/html ; charset=iso-8859-1">
<title>File Upload Form</title>
<script lang="javascript" >
function validate(){
var val=document.getElementById("F1").value;
if(val==""){
alert("Please select a File to upload");
return false;
}
if(val.indexOf("docx") > 0 || val.indexOf("xls")> 0 || val.indexOf("xlsx")> 0 || val.indexOf("csv") >0 || val.indexOf("rtf") > 0 || val.indexOf("doc")> 0 || val.indexOf("ppt") > 0){
alert("These file formats are not supported. Kindly try to upload an Image.")
return false;
}
return true;
}
</script>
</head>
<body>
<h2 align="center">{PNAME} </h2>
<form method="POST" enctype="multipart/form-data" action="uploadFile.jsp?pkey={PKEY}&pname={PNAME}" accept-charset="iso-8859-1" onsubmit="return validate();">
<br>
<center><table border="1" >
<tr><td><b>Choose File:</b>
</td>
<td><input name="F1" id="F1" type="file"></td></tr>
<tr><td colspan="2">
<p align="right"><input type="submit" value="Upload File" ></p></td></tr>
<table>
</cester>
</form>
</body>
</html>
PS: this is perfectly working code applicable for any format and size of images and Text FILES.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
For small files you can do it this way:
(1) Read file from storage into JavaScript variable
(2) Do a BASE64 encode of the String
(3) Send the BASE64 String to SAP MII
(4) Use the Image Writer action to save the BASE64 String to a file
The Image Writer requires a BASE64 string, but saves the unencoded data to MII.
Regards
Tobias
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ayush,
reading the file from the local machine is the hardest task of the four steps.
There is no native way of how to read the file. You can use Flash, Java Applet or some other plugins (like ActiveX or JScript) to read the file.
Maybe someone else has a better solution for reading files.
Regards
Tobias
User | Count |
---|---|
12 | |
7 | |
3 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.