on ‎2008 Feb 07 3:33 PM
Hi
Does anyone know how I can allow a user to upload a document into xMII from their client machine, which I can then store on my xMII server either in an Oracle database or some folder somewhere, or in the DMS
Thanks
Nick
Request clarification before answering.
Nick - there are a lot of HTTP file upload code samples available out there. Just go to google and search, and you will get a long list. The one to choose will be based on your server environment, and maybe the security contraints on your LAN.
There are two basic options for dealing with the file. You can just have it dropped on the web root in a public folder with read/write access, and process it asynchronously with MII BLS, or you can post a document directly to a BLS transaction and process it synchronously (just need to set the post URL up correctly to send it to a specific transaction).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
John
How do I get the transaction to accept the document?
I tried this
<form method=post action="http://desodcwas005:52900/XMII/Runner?Transaction=Users/Nick/docs/test1&OutputParameter=result" ENCTYPE="multipart/form-data">
<INPUT TYPE="file" NAME="blob">
<input type=submit>
</form>
"test1" is a simple transaction with
- "blob" as a text Transaction Input Parameter
- "result" is the output parameter
- One action block assigning the value of blob to result.
but it doesn't do anything.
Any help would be much appreciated.
Thanks
Nick
Nick,
You have to first capture the binary data via posting to a JSP page, "poor mans servlet", where you take the binary data and Base64 encode it. Then perform the call in the code to post the data into the transaction either via SOAPRunner or Runner. Once the string of encoded data is passed into the Transaction you can then use the base64decode method in the link editor to convert the document contents back into binary form. Hope this helps.
Sam
Sorry Sam, really struggling with this one.
Couldn't find any source code examples on the net that used this technique (did find some others that only worked with small files)
Obviously don't expect you to do my job for me (ahem!), but if you have any sample code it'd be much appreciated!!
Also not sure I have the correct JAR files, the only file on my xmii server is
D:\usr\sap\SMD\JC29\j2ee\cluster\server0\apps\sap.com\xappsxmiiear\servlet_jsp\XMII\root\WEB-INF\lib\commons-fileupload-1.0.jar
Is it safe to update this to commons-fileupload-1.2.1.jar ? (from http://commons.apache.org/).
Also think I need commons-io.jar (currently commons-io.1.4.jar from same source)
Thanks
Nick
Nick,
I do not recommend changing any of the system jars as this may affect how MII works and it's not worth the risk.
As for the code examples and large files the Apache site tells you how to handle both, [http://commons.apache.org/fileupload/using.html|http://commons.apache.org/fileupload/using.html]. One thing to keep in mind is the file buffer size you are using may have to be expanded but that's probably all you'll have to change. I have used this library before to upload pictures into my site and haven't had any issues with > 3MB files even with the "simple" version of the code given on the Apache site.
Sam
Hint: I did mention in the previous post which JSP pages use this currently...
Sam
Thanks again, but I'm afraid I still haven't managed to progress very much. I looked at both CustomActionsUpload and JDBCDriverUpload, but they both run off to something called "CMSAdmin", which I can't find.
Basically I think all I am missing is what I have to import at the top of the page (the apache site doesn't tell you in it's worked example). I tried these off another site
page import="org.apache.commons.fileupload.*,
org.apache.commons.fileupload.servlet.ServletFileUpload,
org.apache.commons.fileupload.disk.DiskFileItemFactory, org.apache.commons.io.FilenameUtils,
java.util.*, java.io.File, java.lang.Exception"but got the following errors
package org.apache.commons.fileupload.servlet does not exist
package org.apache.commons.fileupload.disk does not exist
Any ideas?
Thanks
Nick
Nick,
Should just need these libraries:
org.apache.commons.fileupload.DiskFileUpload;
org.apache.commons.fileupload.FileItem;
Then all you need to do is to parse the multipart request to determine the file vs. field items, base 64 encode the file content and add it to your URL. Hope this helps.
Sam
Success!
Thanks very much
It took a bit of mucking about to change the references to the older libraries, so here is the code for anyone else
<%@ page import="org.apache.commons.fileupload.*" %>
<%@ page import="org.apache.commons.fileupload.DiskFileUpload" %>
<%@ page import="org.apache.commons.fileupload.FileItem" %>
<%@ page import="java.util.*" %>
<%@ page import="java.io.File" %>
<%@ page import="java.lang.Exception" %>
<%
// Check that we have a file upload request
boolean isMultipart = DiskFileUpload.isMultipartContent(request);
// Create a factory for disk-based file items
DefaultFileItemFactory factory = new DefaultFileItemFactory();
// Create a new file upload handler
DiskFileUpload upload = new DiskFileUpload(factory);
// Parse the request
List /* FileItem */ items = upload.parseRequest(request);
Iterator iter = items.iterator();
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
if (item.isFormField()) {
} else {
String fieldName = item.getFieldName();
String fileName = item.getName();
String contentType = item.getContentType();
boolean isInMemory = item.isInMemory();
long sizeInBytes = item.getSize();
out.println("fieldName = " + fieldName);
out.println("contentType = " + contentType);
out.println("fileName = " + fileName);
out.println("isInMemory = " + isInMemory);
out.println("sizeInBytes = " + sizeInBytes);
File uploadedFile = new File("d:\\upload\\" + fileName.substring(fileName.lastIndexOf("\\") + 1));
item.write(uploadedFile);
}
}
%>
Hi Nick,
I was wondering if you were still around to help me.
I understand that you got the functionality to work using apache libs.
Can you tell me what does the below URL does?
File uploadedFile = new File("d:\\upload\\" + fileName.substring(fileName.lastIndexOf("\\") + 1));
I mean, is it the link where your file is getting uploaded or the link of the file that you need to upload.
Regards
Anish Vyas
Thnx Sam,
but I know about "WEB..." and etc. I didn't write clearly what I don't know...
I don't know how to "send" file from jsp (above) to the input of transaction.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I finnaly had a need for this functionality. I didn't want to use a BLT so here is what I came up with. I am borrowing some API's so use at your own risk, they may not be supported in the future.
<%@ page import="org.apache.commons.fileupload.DefaultFileItemFactory" %>
<%@ page import="org.apache.commons.fileupload.DiskFileUpload" %>
<%@ page import="org.apache.commons.fileupload.FileItem" %>
<%@ page import="java.util.*" %>
<%@ page import="java.io.File" %>
<%@ page import="java.lang.Exception" %>
<%@ page import="java.lang.String" %>
<%@ page import="com.sap.xmii.Illuminator.security.User" %>
<%@ page import="com.sap.xmii.Illuminator.common.*" %>
<%@ page import="com.sap.xmii.Illuminator.content.ContentManager" %>
<%@ page import="com.sap.xmii.system.SessionHandler" %>
<%@ page import="com.sap.security.api.IUser" %>
<%@ page import="com.sap.security.api.UMFactory" %>
<%
//get our user and check against a custom file upload role.
IUser user = UMFactory.getUserFactory().getUserByUniqueName(SessionHandler.getUser(request).getName());
if(user.isMemberOfRole("ROLE.UME_ROLE_PERSISTENCE.un:CUSTOM_FILE_UPLOAD_ROLE", true)){
if(DiskFileUpload.isMultipartContent(request)){
// Create a factory for disk-based file items
DefaultFileItemFactory factory = new DefaultFileItemFactory();
// Create a new file upload handler
DiskFileUpload upload = new DiskFileUpload(factory);
// Parse the request
List /* FileItem */ items = upload.parseRequest(request);
Iterator iter = items.iterator();
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
if (!item.isFormField()) {
String fileName = item.getName();
String mimeType = getServletContext().getMimeType(fileName);
//we only want to allow images to be uploaded
if(mimeType!=null && mimeType.startsWith("image")){
if(item.getSize()>0){
byte dataBytes[] = item.get();
try {
// FileUpload/FileStore/ will save uploaded file to the MII web container - FileUpload/WEB/FileStore
ContentManager.save("FileUpload/FileStore/" + fileName , dataBytes , SessionHandler.getUser(request), false,null, false);
out.println("<BR> File " + fileName + " Uploaded");
} catch (Exception e) {
out.println("<BR> Error Uploading File " + e.getMessage() );
}
}
}else {
out.println("<BR>Not An Image");
}
}
}
}
}else {
out.println("<BR> USER HAS NO AUTHORITY TO UPLOAD FILES ");
}
%>
Hi...
I am trying to upload file (image) and I am using Nick's code, but I don't see "uploaded" file in MII Workbench (WEB tab).
I am getting message that file is in memory and etc...
"fieldName = path_to_file contentType = image/pjpeg fileName = C:\logistic.jpg isInMemory = true sizeInBytes = 1777 "
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Mat,
Be sure that you use the image saver action in your transaction and save it off to:
WEB://<Project>/<path>/<filename>
The base64 decoding should be automatically handled by this action, whereas you would have to specify the base64decode function in the link editor with the file saver action.
Sam
Nick,
I recommend looking into a JSP page which uses the following apache libs:
org.apache.file-io
org.apache.commons
in order to achieve this scenario. As John mentioned there are plenty of upload scenarios on the web including this one which I have gotten to work in the past with xMII v12.
Hope this helps.
Sam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 1 | |
| 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.